You are here

public function GridStackBase::containerAttributes in GridStack 8.2

Returns the .gridstack container attributes.

Overrides GridStackEnginePluginBase::containerAttributes

File

src/Plugin/gridstack/engine/GridStackBase.php, line 102

Class

GridStackBase
Provides the base class for two-dimensional layout engines.

Namespace

Drupal\gridstack\Plugin\gridstack\engine

Code

public function containerAttributes(array &$attributes, array &$settings) {
  parent::containerAttributes($attributes, $settings);
  $attributes['class'][] = 'gridstack--js';

  // Responsive breakpoint related data-attributes helpers.
  $optionset = $this
    ->getOptionset();
  $attributes['data-gs-min-width'] = $this->minWidth;
  if ($optionset
    ->getSetting('noMargin', FALSE)) {
    $attributes['class'][] = 'is-gs-nomargin';
  }
  if ($vm = $optionset
    ->getSetting('verticalMargin')) {
    $attributes['data-gs-vm'] = $vm / 2;
  }

  // Do not proceed if gridstack is disabled.
  if ($this
    ->getSetting('ungridstack')) {
    $attributes['class'][] = 'ungridstack';
    return;
  }

  // Use the customized gridstack static without dnd if so configured.
  if ($this
    ->getSetting('gridstatic') && !$this
    ->getSetting('gridnative')) {
    $attributes['class'][] = 'gridstack--static';
  }

  // JS-enabled layouts, including native Grid.
  // Cannot rely on the library grid-stack-static, since not always there
  // such as when using native Grid which doesn't load GridStack library.
  if (!$this
    ->getSetting('_ipe')) {
    $attributes['class'][] = 'is-gs-packing';
  }
  $attributes['class'][] = 'is-gs-enabled';

  // Adds attributes for js-driven or native Grid layouts so to be responsive.
  // Supports dynamic like Isotope to have both native CSS and JS layouts.
  $attributes['data-gs-column'] = $optionset
    ->getLastColumn();
  $attributes['data-gs-columns'] = $optionset
    ->getJson('breakpoints');
  $attributes['data-gs-config'] = $optionset
    ->getJson('settings');
  $attributes['data-gs-data'] = $optionset
    ->getData();
}