You are here

public static function Blazy::containerAttributes in Blazy 8

Same name and namespace in other branches
  1. 8.2 src/Blazy.php \Drupal\blazy\Blazy::containerAttributes()
  2. 7 src/Blazy.php \Drupal\blazy\Blazy::containerAttributes()

Provides container attributes for .blazy container: .field, .view, etc.

3 calls to Blazy::containerAttributes()
BlazyGrid::build in src/BlazyGrid.php
Returns items as a grid display wrapped by theme_item_list().
BlazyViews::viewsPreRender in src/BlazyViews.php
Implements hook_views_pre_render().
blazy_preprocess_field in ./blazy.module
Implements hook_preprocess_field().

File

src/Blazy.php, line 151

Class

Blazy
Implements BlazyInterface.

Namespace

Drupal\blazy

Code

public static function containerAttributes(array &$attributes, array $settings = []) {

  // Provides the main container attributes.
  $classes = empty($attributes['class']) ? [] : $attributes['class'];
  $attributes['data-blazy'] = empty($settings['blazy_data']) ? '' : Json::encode($settings['blazy_data']);

  // Provides data-LIGHTBOX-gallery to not conflict with original modules.
  if (!empty($settings['media_switch'])) {
    $switch = str_replace('_', '-', $settings['media_switch']);
    $attributes['data-' . $switch . '-gallery'] = TRUE;
  }

  // Provides contextual classes relevant to the container: .field, or .view.
  if (isset($settings['namespace']) && $settings['namespace'] == 'blazy') {
    foreach ([
      'field',
      'view',
    ] as $key) {
      if (!empty($settings[$key . '_name'])) {
        $classes[] = 'blazy--' . $key . ' blazy--' . str_replace('_', '-', $settings[$key . '_name']);
      }
    }
  }
  $attributes['class'] = array_merge([
    'blazy',
  ], $classes);
}