You are here

public function BlazyManagerBase::attach in Blazy 8.2

Same name and namespace in other branches
  1. 8 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::attach()
  2. 7 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::attach()

Returns array of needed assets suitable for #attached property.

Parameters

array $attach: The settings which determine what library to attach.

Return value

array The supported libraries.

Overrides BlazyManagerInterface::attach

1 call to BlazyManagerBase::attach()
BlazyManagerBase::setAttachments in src/BlazyManagerBase.php
Provides attachments and cache common for all blazy-related modules.

File

src/BlazyManagerBase.php, line 216

Class

BlazyManagerBase
Implements BlazyManagerInterface.

Namespace

Drupal\blazy

Code

public function attach(array $attach = []) {
  $load = [];
  $switch = empty($attach['media_switch']) ? '' : $attach['media_switch'];
  if ($switch && $switch != 'content') {
    $attach[$switch] = $switch;
    if (in_array($switch, $this
      ->getLightboxes())) {
      $load['library'][] = 'blazy/lightbox';
      if (!empty($attach['colorbox'])) {
        BlazyAlter::attachColorbox($load, $attach);
      }
    }
  }

  // Allow both variants of grid or column to co-exist for different fields.
  if (!empty($attach['style'])) {
    $attach[$attach['style']] = $attach['style'];
  }
  if (!empty($attach['fx']) && $attach['fx'] == 'blur') {
    $load['library'][] = 'blazy/fx.blur';
  }
  $components = [
    'column',
    'filter',
    'grid',
    'media',
    'photobox',
    'ratio',
  ];
  foreach ($components as $component) {
    if (!empty($attach[$component])) {
      $load['library'][] = 'blazy/' . $component;
    }
  }

  // Allows Blazy libraries to be disabled by a special flag _unblazy.
  if (empty($attach['_unblazy'])) {
    $load['library'][] = 'blazy/load';
    $load['drupalSettings']['blazy'] = $this
      ->configLoad('blazy');
    $load['drupalSettings']['blazyIo'] = $this
      ->getIoSettings($attach);
  }

  // Adds AJAX helper to revalidate Blazy/ IO, if using VIS, or alike.
  if (!empty($attach['use_ajax'])) {
    $load['library'][] = 'blazy/bio.ajax';
  }
  $this->moduleHandler
    ->alter('blazy_attach', $load, $attach);
  return $load;
}