You are here

public static function BlazyGrid::attributes in Blazy 8.2

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

Provides reusable container attributes.

1 call to BlazyGrid::attributes()
BlazyGrid::build in src/BlazyGrid.php
Returns items wrapped by theme_item_list(), can be a grid, or plain list.

File

src/BlazyGrid.php, line 81

Class

BlazyGrid
Provides grid utilities.

Namespace

Drupal\blazy

Code

public static function attributes(array &$attributes, array $settings = []) {
  $style = empty($settings['style']) ? '' : $settings['style'];
  $is_gallery = !empty($settings['lightbox']) && !empty($settings['gallery_id']);
  $is_grid = isset($settings['_grid']) ? $settings['_grid'] : !empty($settings['style']) && !empty($settings['grid']);

  // Provides data-attributes to avoid conflict with original implementations.
  Blazy::containerAttributes($attributes, $settings);

  // Provides gallery ID, although Colorbox works without it, others may not.
  // Uniqueness is not crucial as a gallery needs to work across entities.
  if (!empty($settings['id'])) {
    $attributes['id'] = $is_gallery ? $settings['gallery_id'] : $settings['id'];
  }

  // Limit to grid only, so to be usable for plain list.
  if ($is_grid) {
    $attributes['class'][] = 'blazy--grid block-' . $style . ' block-count-' . $settings['count'];

    // Adds common grid attributes for CSS3 column, Foundation, etc.
    if ($settings['grid_large'] = $settings['grid']) {
      foreach ([
        'small',
        'medium',
        'large',
      ] as $grid) {
        if (!empty($settings['grid_' . $grid])) {
          $attributes['class'][] = $grid . '-block-' . $style . '-' . $settings['grid_' . $grid];
        }
      }
    }
  }
}