class GridStackLayout in GridStack 8.2
Provides a GridStack class for Layout plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Layout\LayoutDefault implements LayoutInterface, PluginFormInterface
- class \Drupal\gridstack\Plugin\Layout\GridStackLayoutBase implements ContainerFactoryPluginInterface, PluginFormInterface
- class \Drupal\gridstack\Plugin\Layout\GridStackLayout
- class \Drupal\gridstack\Plugin\Layout\GridStackLayoutBase implements ContainerFactoryPluginInterface, PluginFormInterface
- class \Drupal\Core\Layout\LayoutDefault implements LayoutInterface, PluginFormInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GridStackLayout
File
- src/
Plugin/ Layout/ GridStackLayout.php, line 12
Namespace
Drupal\gridstack\Plugin\LayoutView source
class GridStackLayout extends GridStackLayoutBase {
/**
* {@inheritdoc}
*/
public function build(array $regions) {
ksort($regions);
$settings = $this
->getConfiguration();
$definition = $this
->getPluginDefinition();
$name = $definition
->get('optionset');
$optionset = GridStack::loadWithFallback($name);
$variant = $this->manager
->getEngine($settings, 'variant')
->override($optionset, $settings);
// Provides settings.
$settings['optionset'] = $name;
$settings['_stylizer'] = TRUE;
$settings = array_filter($settings);
$build = [
'items' => $this
->interpolateItems($optionset, $settings, $regions),
'optionset' => $optionset,
'settings' => $settings,
'layout' => $definition,
'variant' => $variant,
];
// Still a check in case it is removed by another alter.
if ($library = $this->pluginDefinition
->getLibrary()) {
$build['attached']['library'][] = $library;
}
// Must pass the layout blueprint to Layout Builder regardless empty.
return $this->manager
->build($build);
}
/**
* Interpolate data from Layout Builder to match original construct.
*
* We do this because we don't manually put regions into templates.
* Instead structured with nested grids, if any, to have one template for any
* known layout possibility: one or two dimensional layouts.
* With everything being cached at D8, this shouldn't make much different than
* hard-coded layouts at YML files which still need parsing anyway.
*/
protected function interpolateItems($optionset, array &$settings, array $regions = []) {
$id = 'box';
$items = [];
$config = isset($settings['regions']) ? $settings['regions'] : [];
unset($settings['regions']);
foreach (array_keys($optionset
->getLastBreakpoint()) as $delta) {
$rid = GridStackDefault::regionId($delta);
$box = [];
// Remove top level settings to avoid leaking due to similarity.
$box['settings'] = array_diff_key($settings, GridStackDefault::regionSettings());
$box['settings'] = isset($config[$rid]) ? array_merge($box['settings'], $config[$rid]) : $box['settings'];
if ($grids = $optionset
->getNestedGridsByDelta($delta)) {
foreach (array_keys($grids) as $nid) {
$rid = GridStackDefault::regionId($delta . '_' . $nid);
// @todo recheck $box['settings'] = array_diff_key($box['settings'], GridStackDefault::regionSettings());
// Preserves indices even if empty so to layout for Layout Builder.
$box[$id][$nid][$id] = isset($regions[$rid]) && !Element::isEmpty($regions[$rid]) ? $regions[$rid] : [];
$box[$id][$nid]['settings'] = isset($config[$rid]) ? array_merge($box['settings'], $config[$rid]) : $box['settings'];
}
}
else {
// Preserves indices even if empty so to layout for Layout Builder.
$box[$id] = isset($regions[$rid]) && !Element::isEmpty($regions[$rid]) ? $regions[$rid] : [];
}
$items[] = $box;
unset($box);
}
return $items;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
GridStackLayout:: |
public | function |
Build a render array for layout with regions. Overrides LayoutDefault:: |
|
GridStackLayout:: |
protected | function | Interpolate data from Layout Builder to match original construct. | |
GridStackLayoutBase:: |
protected | property | The gridstack admin service. | |
GridStackLayoutBase:: |
protected | property | The current user. | |
GridStackLayoutBase:: |
protected | property | The field name to store media. | |
GridStackLayoutBase:: |
protected | property | The gridstack manager service. | |
GridStackLayoutBase:: |
protected | property | The gridstack stylizer form plugin. | |
GridStackLayoutBase:: |
protected | property | The gridstack stylizer service. | |
GridStackLayoutBase:: |
public | function |
Form constructor. Overrides LayoutDefault:: |
|
GridStackLayoutBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
GridStackLayoutBase:: |
public | function |
Gets default configuration for this plugin. Overrides LayoutDefault:: |
|
GridStackLayoutBase:: |
protected | function | Massage form values. | |
GridStackLayoutBase:: |
public | function |
Form submission handler. Overrides LayoutDefault:: |
|
GridStackLayoutBase:: |
public | function |
Form validation handler. Overrides LayoutDefault:: |
|
LayoutDefault:: |
protected | property |
The layout definition. Overrides PluginBase:: |
|
LayoutDefault:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
2 |
LayoutDefault:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
LayoutDefault:: |
public | function |
Overrides PluginBase:: |
|
LayoutDefault:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
LayoutDefault:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |