You are here

public static function GridStackLayoutDeprecated::layoutAlter in GridStack 8

Implements hook_layout_alter().

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

File

src/Layout/GridStackLayoutDeprecated.php, line 125

Class

GridStackLayoutDeprecated
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';
    $region_names = [];
    foreach ($regions as $region => $info) {
      $region_names[$region] = $info['label'];
    }

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