You are here

public function GridStackHook::layoutAlter in GridStack 8.2

Implements hook_layout_alter().

File

src/GridStackHook.php, line 146

Class

GridStackHook
Provides GridStack utility methods for Drupal hooks.

Namespace

Drupal\gridstack

Code

public function layoutAlter(&$definitions) {
  $optionsets = $this->manager
    ->entityLoadMultiple('gridstack');
  $excluded = $this->manager
    ->configLoad('excludes', 'gridstack.settings');
  $framework = $this->manager
    ->configLoad('framework', 'gridstack.settings');
  $path = \drupal_get_path('module', 'gridstack');
  $excludes = [
    'default',
  ];
  if (!empty($excluded)) {
    $excludes = array_unique(array_merge($excludes, array_map('trim', explode(",", $excluded))));
  }
  foreach ($optionsets as $key => $optionset) {
    if (in_array($key, $excludes)) {
      continue;
    }
    $static = !empty($framework) && $optionset
      ->getOption('use_framework');
    $id = $optionset
      ->id();
    $layout_id = GridStackDefault::layoutId($id);
    $regions = $optionset
      ->prepareRegions();

    // Defines the layout.
    $definition = [
      'label' => $optionset
        ->label(),
      'category' => $static ? 'GridStack ' . ucwords($framework) : 'GridStack JS',
      'class' => '\\Drupal\\gridstack\\Plugin\\Layout\\GridStackLayout',
      'default_region' => 'gridstack_0',
      'icon' => $optionset
        ->getIconUrl(),
      'id' => $layout_id,
      'provider' => 'gridstack',
      'additional' => [
        'optionset' => $id,
      ],
      'regions' => $regions,
      'theme_hook' => 'gridstack',
      'path' => $path,
      'library' => 'gridstack/layout',
      'config_dependencies' => [
        'config' => [
          'gridstack.optionset.' . $id,
        ],
        'module' => [
          'gridstack',
        ],
      ],
    ];
    $definitions[$layout_id] = new LayoutDefinition($definition);
  }
}