You are here

public function GridStackManager::preRenderGridStack in GridStack 8.2

Same name and namespace in other branches
  1. 8 src/GridStackManager.php \Drupal\gridstack\GridStackManager::preRenderGridStack()

File

src/GridStackManager.php, line 302

Class

GridStackManager
Implements GridStackManagerInterface.

Namespace

Drupal\gridstack

Code

public function preRenderGridStack($element) {
  $build = $element['#build'];
  unset($element['#build']);

  // Build GridStack elements.
  $this
    ->prepareBuild($build, $element);
  $settings =& $build['settings'];

  // Provides cache, attributes, assets.
  // @todo reuse ::setAttachments post blazy:2.1+.
  $cache = $this
    ->getCacheMetadata($build);
  $attributes = $this
    ->prepareAttributes($build);
  $attachments = $this
    ->attach($settings);
  $attachments = empty($build['attached']) ? $attachments : NestedArray::mergeDeep($build['attached'], $attachments);

  // Adds the required elements for the template.
  $element['#optionset'] = $this->optionset;
  $element['#settings'] = empty($element['#settings']) ? $settings : NestedArray::mergeDeep($element['#settings'], $settings);
  $element['#postscript'] = empty($element['#postscript']) ? $build['postscript'] : NestedArray::mergeDeep($element['#postscript'], $build['postscript']);
  $element['#attributes'] = empty($element['#attributes']) ? $attributes : NestedArray::mergeDeep($element['#attributes'], $attributes);
  $element['#attached'] = empty($element['#attached']) ? $attachments : NestedArray::mergeDeep($element['#attached'], $attachments);
  $element['#cache'] = empty($element['#cache']) ? $cache : NestedArray::mergeDeep($element['#cache'], $cache);

  // Layout Builder is happy, safe to free up wasted children.
  foreach (Element::children($element) as $child) {
    unset($element[$child]);
  }
  unset($build);
  return $element;
}