ng_lightbox.module 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @file
  4. * The NG Lightbox module.
  5. */
  6. /**
  7. * Implements hook_link_alter().
  8. */
  9. function ng_lightbox_link_alter(&$vars) {
  10. /** @var \Drupal\ng_lightbox\NgLightbox $lightbox */
  11. $lightbox = \Drupal::service('ng_lightbox');
  12. if ($lightbox->isNgLightboxEnabledPath($vars['url'])) {
  13. $lightbox->addLightbox($vars);
  14. }
  15. elseif (!empty($vars['options']['attributes']['class'])) {
  16. // We have to normalize to an array because many places incorrectly set
  17. // class to a string.
  18. $vars['options']['attributes']['class'] = (array) $vars['options']['attributes']['class'];
  19. if (in_array('ng-lightbox', $vars['options']['attributes']['class'])) {
  20. $lightbox->addLightbox($vars);
  21. }
  22. }
  23. // If you've enabled/disabled the modal for admin paths this allows you to
  24. // override it for one off paths.
  25. \Drupal::moduleHandler()->alter('ng_lightbox_ajax_path', $vars);
  26. }
  27. /**
  28. * Implements hook_page_attachments().
  29. */
  30. function ng_lightbox_page_attachments(array &$attachments) {
  31. $attachments['#attached']['library'][] = 'ng_lightbox/ng_lightbox';
  32. }