You are here

function template_preprocess_gridstack_box in GridStack 8

Same name and namespace in other branches
  1. 8.2 templates/gridstack.theme.inc \template_preprocess_gridstack_box()

Prepares variables for gridstack-box.html.twig templates.

File

templates/gridstack.theme.inc, line 120
Hooks and preprocess functions for the GridStack module.

Code

function template_preprocess_gridstack_box(&$variables) {
  foreach ([
    'attributes',
    'delta',
    'item',
    'settings',
  ] as $key) {
    $variables[$key] = isset($variables['element']["#{$key}"]) ? $variables['element']["#{$key}"] : [];
  }
  $content_attributes =& $variables['content_attributes'];
  $settings =& $variables['settings'];
  $item =& $variables['item'];

  // Boxes may have captions.
  foreach ([
    'alt',
    'data',
    'link',
    'title',
  ] as $key) {
    $item['caption'][$key] = isset($item['caption']) && isset($item['caption'][$key]) ? $item['caption'][$key] : [];
  }
  $item['box'] = isset($item['box']) ? $item['box'] : [];
  $item['caption'] = array_filter($item['caption']);
  $settings['type'] = isset($settings['type']) ? $settings['type'] : '';
  $variables['wrapper'] = empty($settings['wrapper']) ? 'div' : $settings['wrapper'];
  $variables['content_attributes'] = new Attribute($content_attributes);
}