You are here

ng_lightbox.module in NG Lightbox 8

Same filename and directory in other branches
  1. 7 ng_lightbox.module
  2. 2.x ng_lightbox.module

The NG Lightbox module.

File

ng_lightbox.module
View source
<?php

/**
 * @file
 * The NG Lightbox module.
 */

/**
 * Implements hook_link_alter().
 */
function ng_lightbox_link_alter(&$vars) {

  /** @var \Drupal\ng_lightbox\NgLightbox $lightbox */
  $lightbox = \Drupal::service('ng_lightbox');
  if ($lightbox
    ->isNgLightboxEnabledPath($vars['url'])) {
    $lightbox
      ->addLightbox($vars);
  }
  elseif (!empty($vars['options']['attributes']['class'])) {

    // We have to normalize to an array because many places incorrectly set
    // class to a string.
    $vars['options']['attributes']['class'] = (array) $vars['options']['attributes']['class'];
    if (in_array('ng-lightbox', $vars['options']['attributes']['class'])) {
      $lightbox
        ->addLightbox($vars);
    }
  }

  // If you've enabled/disabled the modal for admin paths this allows you to
  // override it for one off paths.
  \Drupal::moduleHandler()
    ->alter('ng_lightbox_ajax_path', $vars);
}

/**
 * Implements hook_page_attachments().
 */
function ng_lightbox_page_attachments(array &$attachments) {
  $attachments['#attached']['library'][] = 'ng_lightbox/ng_lightbox';
}