Skip to content

Instantly share code, notes, and snippets.

View bdecarne's full-sized avatar

Blaise de Carné bdecarne

View GitHub Profile
@bdecarne
bdecarne / retrieve_profile2.module
Created April 7, 2013 08:19
Drupal : Retrieve Profile2 Edit Form Programmatically
<?php
module_load_include('inc', 'profile2_page', 'profile2_page');
$profile2 = profile2_by_uid_load($user->uid, 'profile_id'); // profile_id = machine name
$entity_form = entity_ui_get_form('profile2', $profile2, 'edit');
return $entity_form;
@bdecarne
bdecarne / MY_MODULE.module
Last active December 15, 2015 21:59
Drupal : Add profile2 form directly on the user edit form
<?php
/**
* Implements hook_menu_alter().
*/
function MY_MODULE_menu_alter(&$items) {
$items['user/%user_category/edit/profile']['access callback'] = FALSE;
}
/**
@bdecarne
bdecarne / MY_MODULE.module
Last active December 16, 2015 07:08
Drupal : Add AJAX validation and submit to a regular form
<?php
function MY_MODULE_form_alter(&$form, &$form_state, $form_id)
{
$form['#prefix'] = '<div id="formwrapper">';
$form['#suffix'] = '</div>';
// the submit button
$form['save']['#ajax'] = array(
'callback' => 'MY_MODULE_form_ajax_submit',
'wrapper' => 'formwrapper',
@bdecarne
bdecarne / template.php
Last active December 17, 2015 00:19 — forked from lsolesen/template.php
/**
* Implements hook_menu_local_task()
*
* @param array $variables
*
* return string with html
*/
function mytheme_menu_local_task($variables) {
$link = $variables['element']['#link'];
// remove the view link when viewing the node
@bdecarne
bdecarne / test.module
Created May 31, 2013 09:43
Drupal : Show exposed filters form in a custom block
<?php
/**
* implements hook_block_info()
**/
function test_block_info(){
$blocks = array();
$blocks['custom_exposed_filter_form'] = array(
'info' => t('Exposed filter form'),
'cache' => DRUPAL_NO_CACHE,
@bdecarne
bdecarne / myfeature.module
Created June 4, 2013 10:48
Drupal : Using admin theme for feeds importer
<?php
/**
* Implements hook_admin_paths().
*/
function myfeature_admin_paths() {
$paths = array(
'import' => TRUE,
'import/*' => TRUE,
'node/*/import' => TRUE,
@bdecarne
bdecarne / script.sh
Created June 10, 2013 21:56
Make a programme continue to run after log out from ssh
Assuming that you have a program running in the foreground, press ctrl-Z, then:
[1]+ Stopped myprogram
$ disown -h %1
$ bg 1
[1]+ myprogram &
$ logout
@bdecarne
bdecarne / query
Created July 19, 2013 12:17
Get an ElasticSearch facet based on id with label
{
"query" : { "query_string" : {"query" : "*"} },
"facets" : {
"tag" : {
"terms" : {
"field" : "id",
"script" : "term + \"|\" + _source.nom"
}
}
}
@bdecarne
bdecarne / flashes.html.twig
Created August 23, 2013 17:03
Twig : render all flash messages
{% for label, flashes in app.session.flashbag.all %}
{% for flash in flashes %}
<div class="alert alert-{{ label }}">
{{ flash }}
</div>
{% endfor %}
{% endfor %}
@bdecarne
bdecarne / template.php
Created September 10, 2013 13:01
Views Slideshow Cycle : pagination adaptation for multiple items per slide
<?php
/**
* Implements hook_preprocess_views_slideshow_pager_fields()
*/
function MYTHEME_preprocess_views_slideshow_pager_fields(&$vars) {
$slide_count = count($vars['view']->result);
$items_per_slide = $vars['view']->style_options['views_slideshow_cycle']['items_per_slide'];
if ($vars['view']->style_options['slideshow_type'] == 'views_slideshow_cycle') {