public static function BlazyViews::viewsPreRender in Blazy 8
Same name and namespace in other branches
- 8.2 src/BlazyViews.php \Drupal\blazy\BlazyViews::viewsPreRender()
Implements hook_views_pre_render().
1 call to BlazyViews::viewsPreRender()
- blazy_views_pre_render in ./blazy.module 
- Implements hook_views_pre_render().
File
- src/BlazyViews.php, line 15 
Class
- BlazyViews
- Provides optional Views integration.
Namespace
Drupal\blazyCode
public static function viewsPreRender($view) {
  // Load Blazy library once, not per field, if any Blazy Views field found.
  if ($blazy = self::viewsField($view)) {
    $plugin_id = $view
      ->getStyle()
      ->getPluginId();
    $settings = $blazy
      ->mergedViewsSettings();
    $load = $blazy
      ->blazyManager()
      ->attach($settings);
    // Enforce Blazy to work with hidden element such as with EB selection.
    $load['drupalSettings']['blazy']['loadInvisible'] = TRUE;
    $view->element['#attached'] = isset($view->element['#attached']) ? NestedArray::mergeDeep($view->element['#attached'], $load) : $load;
    $grid = $plugin_id == 'blazy';
    if ($options = $view
      ->getStyle()->options) {
      $grid = empty($options['grid']) ? $grid : TRUE;
    }
    // Prevents dup [data-LIGHTBOX-gallery] if the Views style supports Grid.
    if (!$grid) {
      // @todo remove conditions when confident, kept to avoid the unexpected.
      $view->element['#attributes'] = empty($view->element['#attributes']) ? [] : $view->element['#attributes'];
      Blazy::containerAttributes($view->element['#attributes'], $settings);
    }
  }
}