Drupal 7 Snippet: Add lightbox fallback for image_link_formatter

Drupal 7 Snippet: Add lightbox fallback for image_link_formatter

Little Drupal 7 snippet for the image_link_formatter module (https://www.drupal.org/project/image_link_formatter) to add a fallback to lightbox in size large if no link is given.
Should work the same with other fallbacks (colorbox, etc.).

With some time you could create a clean field formatter from this containing the hard coded values as field display settings.

  1. /**
  2.  * Implements hook_preprocess_field().
  3.  */
  4. function MYMODULE_preprocess_field(&$variables) {
  5.   if(!empty($variables['element'])){
  6.     $element = &$variables['element'];
  7.     if($element['#formatter'] == 'image_link_formatter'){
  8.       if(empty($element[0]['#path']['path'])){
  9.         $element['#formatter'] = 'lightbox2';
  10.         $element[0]['#lightbox_type'] = 'lightbox';
  11.         $element[0]['#caption'] = 'title';
  12.         $element[0]['#field_name'] = ' field_image';
  13.         $element[0]['#lightbox_style'] = 'large';
  14.         $element[0]['#theme'] = 'lightbox2_image';
  15.         // Also set on items:
  16.         $variables['items'][0] = $element;
  17.       }
  18.     }
  19.   }
  20. }

Please leave a short comment if this snippet was helpful for you.

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt. Wenn Sie ein zulässiges Avatar mit Ihrer E-Mail-Adresse verknüpft haben, wird dieses als Avatar verwendet.

Weitere Informationen über Formatierungsoptionen