You are here

function blazy_photoswipe_blazy_attach_alter in Blazy PhotoSwipe 7

Same name and namespace in other branches
  1. 8 blazy_photoswipe.module \blazy_photoswipe_blazy_attach_alter()

Implements hook_blazy_attach_alter().

File

./blazy_photoswipe.module, line 56
Provides a simple Blazy PhotoSwipe integration.

Code

function blazy_photoswipe_blazy_attach_alter(array &$load, $attach = []) {
  if (!photoswipe_assets_loaded() && !empty($attach['photoswipe'])) {
    libraries_load('photoswipe');
    $template = [
      '#theme' => 'photoswipe_container',
    ];
    $template = preg_replace([
      '/<!--(.|\\s)*?-->/',
      '/\\s+/',
    ], ' ', drupal_render($template));
    $options = variable_get('photoswipe_settings', photoswipe_get_default_settings());
    drupal_alter('blazy_photoswipe_js_options', $options, $attach);
    $load['js'][] = [
      'data' => [
        'photoswipe' => [
          'options' => $options,
          'container' => trim($template),
        ],
      ],
      'type' => 'setting',
    ];
    $load['library'][] = [
      'blazy_photoswipe',
      'load',
    ];
    photoswipe_assets_loaded(TRUE);
  }
}