Skip to content

Instantly share code, notes, and snippets.

@aquelito
Last active February 9, 2019 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aquelito/8325756 to your computer and use it in GitHub Desktop.
Save aquelito/8325756 to your computer and use it in GitHub Desktop.
Drupal Snippet
drupal_get_path('theme', $theme_name) . '/path/to/image.jpg', 'alt' => $alt_text, 'width' => $image_width, 'height' => $image_height, 'attributes' => array( 'class' => $image_class, 'id' => $image_id )) ); // $form['title'] = array( // '#type' => 'text_format', // '#title' => t('Enter your text here in WYSIWYG format'), // '#default_value' => variable_get('text_variable', ''), // ); // // File selection form element // $form['file'] = array( // '#name' => 'block_image', // '#type' => 'managed_file', // '#title' => t('Choose an Image File'), // '#description' => t('Select an Image for the custom block. Only *.gif, *.png, *.jpg, and *.jpeg images allowed.'), // '#default_value' => variable_get('block_image_fid', ''), // '#upload_location' => 'public://block_image/', // '#upload_validators' => array( // 'file_validate_extensions' => array('gif png jpg jpeg'), // ), // ); ?>

Drupal Snippet

Debug

  <?php drupal_set_message("<pre>".print_r($page['content'], true)."</pre>"); ?>
  
  watchdog('vinci_tracker', 'Tracker :: visiteonline = %name', array('%name' => 'Vinci_Display'));
_form_element($variables) { $element = $variables['element']; // Disable radio button N/A if ($element['#type'] == 'radio' && $element['#return_value'] === '_none') { $variables['element']['#attributes']['disabled'] = TRUE; } return theme_form_element($variables); } ?>

Convertir l'url d'une image

  <?php file_build_uri($path); ?>

Trouver l'URL d'un node

Avec nid appeller le lien vers le node

<?php
  $options = array('absolute' => TRUE);
  $url = url('node/' . $fields['nid']->content, $options);
?>

Lien Text

<?php
  print l('Libellé du lien', 'node/ID', array(
      'attributes' => array(
        'id'    => array('MON_ID'),
        'class' => array('MA_CLASSE')
      ),
      'html' => true
  ));
?>
<?php print l('Libellé du lien', 'node/ID'); ?>

Pluriel

<?php print format_plural($count, t("@count comment"), t("@count comments")); ?>

Trouver une valeur

<?php
  $field_name = 'field_name';
  $items_name = field_get_items('node', $currentnode, $field_name);
  $vars['name_output'] = field_view_value('node', $currentnode, $field_name, $items_name [0]);
?>

Afficher un block dans un tpl

<?php
  $block = block_load('block', '5');
  $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
  print $output;
?>
$block = block_load('search', '0');

Trouver un block avec son ID

<?php
  $blocks_to_render = array('14', '23', '12', '13');
  foreach ($blocks_to_render as $idblock) {
    $block = module_invoke('block', 'block_view', $idblock);
    $blocks[] = render($block['content']);
  }
  $rand_keys = array_rand($blocks, 1);
  echo $blocks[$rand_keys[0]] . "\n";i
?>

Aller sur le site pour plus d'infos http://www.wdtutorials.com/2012/04/16/drupal-7-how-print-blocks-templates#.UlexTlDIWM4

Supprimer les JS system

<?php
  function starter_js_alter(&$js)
  {
    unset($js[drupal_get_path('module', 'panels').'/js/panels.js']);
    unset($js[drupal_get_path('module', 'views').'/js/views.js']);
    unset($js[drupal_get_path('module', 'views').'/js/ajax_view.js']);
    unset($js[drupal_get_path('module', 'views').'/js/base.js']);
  }
?>

Get path page

<?php
  $path = trim($_GET['q'], '/');         // get the current normal drupal path
  $path = drupal_get_path_alias($path);  // get its alias
  $path = explode('/', $path);           // and break it up
  if (path[0] == 'users' ) {
    // do something
  }
?>

Invoker un block view dans

print views_embed_view('user_domain', 'block_1');

# Block content
$block = module_invoke('views', 'block_view', 'user_domain-block_1');
print $block['content']['#markup'];

Recette / Prod / Auto référencement

<?php if ($_SERVER['SERVER_NAME'] !== 'aquelito.fr'): ?>
  <meta name="robots" content="noindex, nofollow" />  
<?php endif ?>
function default_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form_id) && $form_id === 'views_exposed_form')
  {
    $form['submit']['#value'] = t('Apply');
    $form['reset']['#value'] = t('Reset');
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment