You are here

function lightbox2_link_alter in Lightbox2 8

Same name and namespace in other branches
  1. 5.2 lightbox2.module \lightbox2_link_alter()
  2. 6 lightbox2.module \lightbox2_link_alter()
  3. 7.2 lightbox2.module \lightbox2_link_alter()
  4. 7 lightbox2.module \lightbox2_link_alter()

Implementation of hook_link_alter().

Add a lightbox2 rel attribute to the image link sizes on the image node.

File

./lightbox2.module, line 1682
Enables the use of lightbox2 which places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths.

Code

function lightbox2_link_alter(&$links, $node) {
  $image_node_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_image_node');

  // Only operate on image nodes and if automatic handling for image nodes is
  // enabled.  Also ensure $links is an array (bug in contemplate module).
  if (!$image_node_handler || $node->type != 'image' && $image_node_handler || !is_array($links)) {
    return;
  }

  // @FIXME
  // Could not extract the default value because it is either indeterminate, or
  // not scalar. You'll need to provide a default value in
  // config/install/lightbox2.settings.yml and config/schema/lightbox2.schema.yml.
  $trigger_sizes = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_trigger_image_size');

  // Change original ('original') to '_original'.
  if (isset($trigger_sizes['original'])) {
    unset($trigger_sizes['original']);
    $trigger_sizes['_original'] = '_original';
  }
  $rel = '';
  switch ($image_node_handler) {
    case 1:

    // Lightbox.
    case 2:

    // Lightbox grouped.
    case 3:

      // Slideshow.
      $rel = 'lightbox';
      break;
    case 4:

    // Lightframe.
    case 5:

      // Lightframe grouped.
      $rel = 'lightframe';
      break;
  }
  $rel = $rel . '[][' . $node->title . ']';
  foreach ($trigger_sizes as $size) {
    if (isset($links['image_size_' . $size])) {
      $links['image_size_' . $size]['attributes']['rel'] = $rel;
      $links['image_size_' . $size]['href'] = $node->images[$size];
      unset($links['image_size_' . $size]['query']);
    }
  }
}