You are here

public static function GridStackLayout::layoutAlter in GridStack 8

Implements hook_layout_alter().

1 call to GridStackLayout::layoutAlter()
gridstack_layout_alter in ./gridstack.module
Implements hook_layout_alter().

File

src/Layout/GridStackLayout.php, line 133

Class

GridStackLayout
Provides a GridStack class for Layout plugins.

Namespace

Drupal\gridstack\Layout

Code

public static function layoutAlter(&$definitions) {
  $manager = \Drupal::service('gridstack.manager');
  $optionsets = $manager
    ->entityLoadMultiple('gridstack');
  $framework = $manager
    ->configLoad('framework', 'gridstack.settings');
  $path = drupal_get_path('module', 'gridstack');
  foreach ($optionsets as $key => $optionset) {
    if ($key == 'default') {
      continue;
    }
    $static = !empty($framework) && $optionset
      ->getOption('use_framework');
    $id = $optionset
      ->id();
    $layout_id = 'gridstack_' . $id;
    $regions = self::prepareRegions($optionset);
    $default = isset($regions['gridstack_0']) ? 'gridstack_0' : 'gridstack_0_0';
    $additional = [
      'optionset' => $id,
    ];

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