You are here

public function BlazyManagerBase::isBlazy in Blazy 8.2

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

Checks for Blazy formatter such as from within a Views style plugin.

Ensures the settings traverse up to the container where Blazy is clueless. The supported plugins can add [data-blazy] attribute into its container containing $settings['blazy_data'] converted into [data-blazy] JSON. This allows Blazy Grid, or other Views styles, lacking of UI, to have additional settings extracted from the first Blazy formatter found. Such as media switch/ lightbox. This way the container can add relevant attributes to its container, etc. Also applies to entity references where Blazy is not the main formatter, instead embedded as part of the parent's.

This fairly complex logic is intended to reduce similarly complex logic at individual item. But rather than at individual item, it is executed once at the container level. If you have 100 images, this method is executed once, not 100x, as long as you have all image styles cropped, not scaled.

This still needs improvements and a little more simplified version.

Parameters

array $settings: The settings being modified.

array $item: The first item containing settings or item keys.

Overrides BlazyManagerInterface::isBlazy

See also

\Drupal\blazy\BlazyManager::prepareBuild()

\Drupal\blazy\Dejavu\BlazyEntityBase::buildElements()

1 call to BlazyManagerBase::isBlazy()
BlazyManager::getSettings in src/BlazyManager.php
Prepares Blazy settings.

File

src/BlazyManagerBase.php, line 345

Class

BlazyManagerBase
Implements BlazyManagerInterface.

Namespace

Drupal\blazy

Code

public function isBlazy(array &$settings, array $item = []) {

  // Retrieves Blazy formatter related settings from within Views style.
  $item_id = isset($settings['item_id']) ? $settings['item_id'] : 'x';
  $content = isset($item[$item_id]) ? $item[$item_id] : $item;
  $image = isset($item['item']) ? $item['item'] : NULL;

  // 1. Blazy formatter within Views fields by supported modules.
  $settings['_item'] = $image;
  if (isset($item['settings'])) {
    $this
      ->isBlazyFormatter($settings, $item);
  }

  // 2. Blazy Views fields by supported modules.
  // Prevents edge case with unexpected flattened Views results which is
  // normally triggered by checking "Use field template" option.
  if (is_array($content) && isset($content['#view']) && ($view = $content['#view'])) {
    if ($blazy_field = BlazyViews::viewsField($view)) {
      $settings = array_merge(array_filter($blazy_field
        ->mergedViewsSettings()), array_filter($settings));
    }
  }
  unset($settings['first_image']);
}