You are here

public function GridStackManager::attach in GridStack 8

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

File

src/GridStackManager.php, line 62

Class

GridStackManager
Implements GridStackManagerInterface.

Namespace

Drupal\gridstack

Code

public function attach($attach = []) {
  $attach += [
    'skin' => FALSE,
  ];
  $load = parent::attach($attach);

  // Only load GridStack JS if not using Bootstrap, nor Foundation.
  if (!empty($attach['use_js'])) {
    $customized = $this
      ->configLoad('customized', 'gridstack.settings');
    $load['library'][] = empty($customized) ? 'gridstack/load' : 'gridstack/customized';
    if (!empty($attach['width']) && $attach['width'] < 12) {
      $load['library'][] = 'gridstack/gridstack.' . $attach['width'];
    }

    // Breakpoints: xs sm md lg requires separate CSS files.
    if (!empty($attach['breakpoints'])) {
      foreach ($attach['breakpoints'] as $breakpoint) {
        if (!empty($breakpoint['column']) && $breakpoint['column'] < 12) {
          $load['library'][] = 'gridstack/gridstack.' . $breakpoint['column'];
        }
      }
    }
    $load['drupalSettings']['gridstack'] = GridStack::load('default')
      ->getOptions('settings');
  }
  if (!empty($attach['library'])) {
    $load['library'][] = $attach['library'];
  }

  // Skins may be available for JS, or CSS layouts.
  if ($skin = $attach['skin']) {
    $skins = $this
      ->getSkins();
    $provider = isset($skins[$skin]['provider']) ? $skins[$skin]['provider'] : 'gridstack';
    $load['library'][] = 'gridstack/' . $provider . '.' . $skin;
  }
  $this->moduleHandler
    ->alter('gridstack_attach', $load, $attach);
  return $load;
}