class GridStackLayoutDeprecated in GridStack 8
Provides a GridStack class for Layout plugins.
@todo: Remove for Drupal 8.x-3.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\layout_plugin\Plugin\Layout\LayoutBase implements ConfigurablePluginInterface, PluginFormInterface, LayoutInterface
- class \Drupal\gridstack\Layout\GridStackLayoutDeprecated implements ContainerFactoryPluginInterface, PluginFormInterface, LayoutInterface uses GridStackLayoutTrait
- class \Drupal\layout_plugin\Plugin\Layout\LayoutBase implements ConfigurablePluginInterface, PluginFormInterface, LayoutInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GridStackLayoutDeprecated
File
- src/
Layout/ GridStackLayoutDeprecated.php, line 23
Namespace
Drupal\gridstack\LayoutView source
class GridStackLayoutDeprecated extends LayoutBase implements ContainerFactoryPluginInterface, LayoutInterface, PluginFormInterface {
use GridStackLayoutTrait;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user, GridStackManagerInterface $manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('gridstack.manager'));
}
/**
* {@inheritdoc}
*/
public function build(array $regions) {
$config = $this
->getConfiguration();
$definition = $this
->getPluginDefinition();
$id = $definition['id'];
$item_id = 'box';
$name = $definition['optionset'];
$optionset = GridStack::load($name);
$grids = $optionset
->getEndBreakpointGrids();
$ipe_exists = $this->manager
->getModuleHandler()
->moduleExists('panels_ipe');
// Only check that Panels IPE is granted. Further access check is not here.
// @see \Drupal\gridstack\GridStackManager::preRenderGridStack()
$config['_ipe'] = FALSE;
if ($ipe_exists && $this->currentUser
->hasPermission('access panels in-place editing')) {
$config['_ipe'] = TRUE;
}
// Converts string to array.
$config['extras'] = empty($config['extras']) ? [] : Json::decode($config['extras']);
// Defines settings.
$settings = [
'id' => $id,
'item_id' => $item_id,
'namespace' => 'gridstack',
'optionset' => $name,
] + $config;
// Converts gridstack breakpoint grids from stored JSON into array.
$optionset
->gridsJsonToArray($settings);
$items = [];
foreach ($grids as $delta => $grid) {
$region = 'gridstack_' . $delta;
$box = [];
$box_settings = $settings;
unset($box_settings['attributes'], $box_settings['wrapper'], $box_settings['wrapper_classes']);
$box['settings'] = $box_settings;
$nested_grids = $optionset
->getNestedGridsByDelta($delta);
$is_nested = array_filter($nested_grids);
if (!empty($is_nested)) {
foreach ($nested_grids as $key => $nested_grid) {
$nested_id = $delta . '_' . $key;
$region = 'gridstack_' . $nested_id;
// Preserves indices even if empty.
$box[$item_id][$key][$item_id] = isset($regions[$region]) && !Element::isEmpty($regions[$region]) ? $regions[$region] : [];
}
}
else {
// Preserves indices even if empty.
$box[$item_id] = isset($regions[$region]) && !Element::isEmpty($regions[$region]) ? $regions[$region] : [];
}
$items[] = $box;
unset($box);
}
$build = [
'items' => $items,
'optionset' => $optionset,
'settings' => $settings,
];
return empty($items) ? [] : $this->manager
->build($build);
}
/**
* Implements hook_layout_alter().
*/
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;
}
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// This form may be loaded as a subform by Field Layout, Panels, etc.
// @see https://www.drupal.org/node/2536646
// @see https://www.drupal.org/node/2798261
// @see https://www.drupal.org/node/2774077
// @todo: Remove when no more issues with it.
if ($form_state instanceof SubformStateInterface) {
$form_state = $form_state
->getCompleteFormState();
}
$access = $this->currentUser
->hasPermission('administer gridstack');
$config = $this
->getConfiguration();
$definition = $this
->getPluginDefinition();
$regions = $this
->getRegionDefinitions();
$name = $definition['optionset'];
$optionset = GridStack::load($name);
$regions_all = self::prepareRegions($optionset, FALSE);
$extras = [];
/** @var \Drupal\field_ui\Form\EntityViewDisplayEditForm $entity_form */
$entity_form = $form_state
->getFormObject();
/* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
if (method_exists($entity_form, 'getEntity') && ($display = $entity_form
->getEntity())) {
$extras = [
'bundle' => $display
->getTargetBundle(),
'entity_type' => $display
->getTargetEntityTypeId(),
'view_mode' => $display
->getMode(),
];
}
$settings = [];
foreach ([
'attributes',
'wrapper_classes',
'skin',
'wrapper',
] as $key) {
$default = $key == 'wrapper' ? 'div' : '';
$default = isset($config[$key]) ? $config[$key] : $default;
$settings[$key] = $form_state
->getValue([
'settings',
$key,
], $default);
}
$prefix = '<h3>';
if ($this->manager
->getModuleHandler()
->moduleExists('gridstack_ui') && $access) {
$prefix .= $this
->t('Outer wrapper settings [<small><a href=":url">Edit @id</a></small>]', [
':url' => $optionset
->toUrl('edit-form')
->toString(),
'@id' => strip_tags($optionset
->label()),
]);
}
else {
$prefix .= $this
->t('Outer wrapper settings');
}
$prefix .= '</h3>';
$form['settings'] = [
'#type' => 'container',
'#tree' => TRUE,
'#weight' => 20,
'#prefix' => $prefix,
];
$form['settings']['skin'] = [
'#type' => 'select',
'#title' => $this
->t('Skin'),
'#options' => $this->manager
->getSkinOptions(),
'#empty_option' => $this
->t('- None -'),
'#description' => $this
->t('Choose a skin to load for this layout. Check out, or clone, gridstack_example.module to register skins here. Leave empty to disable.'),
'#default_value' => $settings['skin'],
'#prefix' => '<div class="form-wrapper form-wrapper--inline form-wrapper--left">',
];
$form['settings']['extras'] = [
'#type' => 'hidden',
'#value' => empty($extras) ? '' : Json::encode($extras),
];
$form['settings'] += $this
->buildFormElements($settings);
$closing = '</div><div class="form-wrapper form-wrapper--inline form-wrapper--icon form-wrapper--right">';
if ($uri = $optionset
->getIconUri()) {
$image = [
'#theme' => 'image',
'#uri' => $uri,
'#alt' => $this
->t('Thumbnail'),
];
$closing .= $this->manager
->getRenderer()
->render($image);
}
$closing .= '</div>';
$form['settings']['attributes']['#suffix'] = $closing;
$form['regions'] = [
'#type' => 'container',
'#tree' => TRUE,
'#prefix' => '<p>' . $this
->t('A region has direct contents. A container contains a single, or multiple regions, grouped by their container index.') . '</p>',
];
$settings = [];
foreach ($regions_all as $region => $info) {
foreach ([
'attributes',
'wrapper_classes',
'wrapper',
] as $key) {
$default = $key == 'wrapper' ? 'div' : '';
$default = isset($config['regions'][$region][$key]) ? $config['regions'][$region][$key] : $default;
$default = $form_state
->getValue([
'regions',
$region,
$key,
], $default);
$settings['regions'][$region][$key] = $default;
}
$prefix = !array_key_exists($region, $regions) ? 'Container' : 'Region';
$form['regions'][$region] = [
'#type' => 'details',
'#title' => $this
->t('@prefix: <em>@label</em>', [
'@prefix' => $prefix,
'@label' => $info['label'],
]),
'#open' => TRUE,
'#tree' => TRUE,
'#attributes' => [
'class' => [
'form-wrapper',
'form-wrapper--inline',
],
],
];
$form['regions'][$region] += $this
->buildFormElements($settings['regions'][$region]);
}
$form['#attached']['library'][] = 'gridstack/admin_base';
return $form;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$dependencies['module'][] = 'gridstack';
return $dependencies;
}
}
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 | |
GridStackLayoutDeprecated:: |
public | function |
Build a render array for layout with regions. Overrides LayoutBase:: |
|
GridStackLayoutDeprecated:: |
public | function |
Form constructor. Overrides LayoutBase:: |
|
GridStackLayoutDeprecated:: |
public | function |
Calculates dependencies for the configured plugin. Overrides LayoutBase:: |
|
GridStackLayoutDeprecated:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
GridStackLayoutDeprecated:: |
public static | function | Implements hook_layout_alter(). | |
GridStackLayoutDeprecated:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
GridStackLayoutTrait:: |
protected | property | The current user. | |
GridStackLayoutTrait:: |
protected | property | The gridstack manager service. | |
GridStackLayoutTrait:: |
public | function | ||
GridStackLayoutTrait:: |
public | function | ||
GridStackLayoutTrait:: |
public static | function | Returns regions based on available grids. | |
GridStackLayoutTrait:: |
public | function | ||
GridStackLayoutTrait:: |
public | function | ||
LayoutBase:: |
protected | property |
The layout configuration. Overrides PluginBase:: |
|
LayoutBase:: |
public | function | Gets the path to resources like icon or template. | |
LayoutBase:: |
public | function | Gets the human-readable category. | |
LayoutBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
|
LayoutBase:: |
public | function | Gets the optional description for advanced layouts. | |
LayoutBase:: |
public | function | Gets the path to the preview image. | |
LayoutBase:: |
public | function | Gets the human-readable name. | |
LayoutBase:: |
public | function | Get the asset library. | |
LayoutBase:: |
public | function | Gets information on regions keyed by machine name. | |
LayoutBase:: |
public | function | Gets human-readable list of regions keyed by machine name. | |
LayoutBase:: |
public | function | Gets the theme hook used to render this layout. | |
LayoutBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 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 definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
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. |