You are here

function hook_blazy_attach_alter in Blazy 7

Same name and namespace in other branches
  1. 8.2 blazy.api.php \hook_blazy_attach_alter()
  2. 8 blazy.api.php \hook_blazy_attach_alter()

Alters Blazy attachments to add own library, drupalSettings, and JS template.

Parameters

array $load: The array of loaded library being modified.

array $settings: The available array of settings.

Related topics

1 invocation of hook_blazy_attach_alter()
BlazyManagerBase::attach in src/BlazyManagerBase.php
Returns array of needed assets suitable for #attached property.

File

./blazy.api.php, line 164
Hooks and API provided by the Blazy module.

Code

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