Loading core/config/schema/core.data_types.schema.yml +5 −0 Original line number Diff line number Diff line Loading @@ -362,6 +362,11 @@ layout_plugin.settings: label: type: label label: 'Label' context_mapping: type: sequence label: 'Context assignments' sequence: type: string layout_plugin.settings.*: type: layout_plugin.settings Loading core/lib/Drupal/Core/Layout/LayoutDefault.php +7 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait; use Drupal\Core\Plugin\ContextAwarePluginTrait; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\PluginFormInterface; Loading @@ -12,6 +14,9 @@ */ class LayoutDefault extends PluginBase implements LayoutInterface, PluginFormInterface { use ContextAwarePluginAssignmentTrait; use ContextAwarePluginTrait; /** * The layout definition. * Loading Loading @@ -95,6 +100,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#title' => $this->t('Administrative label'), '#default_value' => $this->configuration['label'], ]; $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: []; $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts); return $form; } Loading core/lib/Drupal/Core/Layout/LayoutDefinition.php +14 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Drupal\Core\Layout; use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface; use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionTrait; use Drupal\Component\Plugin\Definition\DerivablePluginDefinitionInterface; use Drupal\Component\Plugin\Definition\PluginDefinitionInterface; use Drupal\Component\Plugin\Definition\PluginDefinition; Loading @@ -11,8 +13,9 @@ /** * Provides an implementation of a layout definition and its metadata. */ class LayoutDefinition extends PluginDefinition implements PluginDefinitionInterface, DerivablePluginDefinitionInterface, DependentPluginDefinitionInterface { class LayoutDefinition extends PluginDefinition implements PluginDefinitionInterface, DerivablePluginDefinitionInterface, DependentPluginDefinitionInterface, ContextAwarePluginDefinitionInterface { use ContextAwarePluginDefinitionTrait; use DependentPluginDefinitionTrait; /** Loading Loading @@ -129,6 +132,16 @@ class LayoutDefinition extends PluginDefinition implements PluginDefinitionInter * An array of values from the annotation. */ public function __construct(array $definition) { // If there are context definitions in the plugin definition, they should // be added to this object using ::addContextDefinition() so that they can // be manipulated using other ContextAwarePluginDefinitionInterface methods. if (isset($definition['context_definitions'])) { foreach ($definition['context_definitions'] as $name => $context_definition) { $this->addContextDefinition($name, $context_definition); } unset($definition['context_definitions']); } foreach ($definition as $property => $value) { $this->set($property, $value); } Loading core/lib/Drupal/Core/Layout/LayoutInterface.php +2 −1 Original line number Diff line number Diff line Loading @@ -6,11 +6,12 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Plugin\ContextAwarePluginInterface; /** * Provides an interface for static Layout plugins. */ interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface { interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ContextAwarePluginInterface { /** * Build a render array for layout with regions. Loading core/modules/layout_builder/layout_builder.post_update.php +33 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,11 @@ * Post update functions for Layout Builder. */ use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface; /** * Implements hook_removed_post_updates(). */ Loading Loading @@ -34,3 +39,31 @@ function layout_builder_removed_post_updates() { function layout_builder_post_update_override_entity_form_controller() { // Empty post-update hook. } /** * Update view displays that use Layout Builder to add empty context mappings. */ function layout_builder_post_update_section_storage_context_mapping(&$sandbox = []) { $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class); $callback = function (EntityViewDisplayInterface $display) { $needs_update = FALSE; // Only update entity view displays where Layout Builder is enabled. if ($display instanceof LayoutEntityDisplayInterface && $display->isLayoutBuilderEnabled()) { foreach ($display->getSections() as $section) { // Add an empty context mapping to each section where one doesn't exist. $section->setLayoutSettings($section->getLayoutSettings() + [ 'context_mapping' => [], ]); // Flag this display as needing to be updated. $needs_update = TRUE; } } return $needs_update; }; $config_entity_updater->update($sandbox, 'entity_view_display', $callback); } Loading
core/config/schema/core.data_types.schema.yml +5 −0 Original line number Diff line number Diff line Loading @@ -362,6 +362,11 @@ layout_plugin.settings: label: type: label label: 'Label' context_mapping: type: sequence label: 'Context assignments' sequence: type: string layout_plugin.settings.*: type: layout_plugin.settings Loading
core/lib/Drupal/Core/Layout/LayoutDefault.php +7 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait; use Drupal\Core\Plugin\ContextAwarePluginTrait; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\PluginFormInterface; Loading @@ -12,6 +14,9 @@ */ class LayoutDefault extends PluginBase implements LayoutInterface, PluginFormInterface { use ContextAwarePluginAssignmentTrait; use ContextAwarePluginTrait; /** * The layout definition. * Loading Loading @@ -95,6 +100,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#title' => $this->t('Administrative label'), '#default_value' => $this->configuration['label'], ]; $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: []; $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts); return $form; } Loading
core/lib/Drupal/Core/Layout/LayoutDefinition.php +14 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Drupal\Core\Layout; use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface; use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionTrait; use Drupal\Component\Plugin\Definition\DerivablePluginDefinitionInterface; use Drupal\Component\Plugin\Definition\PluginDefinitionInterface; use Drupal\Component\Plugin\Definition\PluginDefinition; Loading @@ -11,8 +13,9 @@ /** * Provides an implementation of a layout definition and its metadata. */ class LayoutDefinition extends PluginDefinition implements PluginDefinitionInterface, DerivablePluginDefinitionInterface, DependentPluginDefinitionInterface { class LayoutDefinition extends PluginDefinition implements PluginDefinitionInterface, DerivablePluginDefinitionInterface, DependentPluginDefinitionInterface, ContextAwarePluginDefinitionInterface { use ContextAwarePluginDefinitionTrait; use DependentPluginDefinitionTrait; /** Loading Loading @@ -129,6 +132,16 @@ class LayoutDefinition extends PluginDefinition implements PluginDefinitionInter * An array of values from the annotation. */ public function __construct(array $definition) { // If there are context definitions in the plugin definition, they should // be added to this object using ::addContextDefinition() so that they can // be manipulated using other ContextAwarePluginDefinitionInterface methods. if (isset($definition['context_definitions'])) { foreach ($definition['context_definitions'] as $name => $context_definition) { $this->addContextDefinition($name, $context_definition); } unset($definition['context_definitions']); } foreach ($definition as $property => $value) { $this->set($property, $value); } Loading
core/lib/Drupal/Core/Layout/LayoutInterface.php +2 −1 Original line number Diff line number Diff line Loading @@ -6,11 +6,12 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Plugin\ContextAwarePluginInterface; /** * Provides an interface for static Layout plugins. */ interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface { interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ContextAwarePluginInterface { /** * Build a render array for layout with regions. Loading
core/modules/layout_builder/layout_builder.post_update.php +33 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,11 @@ * Post update functions for Layout Builder. */ use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface; /** * Implements hook_removed_post_updates(). */ Loading Loading @@ -34,3 +39,31 @@ function layout_builder_removed_post_updates() { function layout_builder_post_update_override_entity_form_controller() { // Empty post-update hook. } /** * Update view displays that use Layout Builder to add empty context mappings. */ function layout_builder_post_update_section_storage_context_mapping(&$sandbox = []) { $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class); $callback = function (EntityViewDisplayInterface $display) { $needs_update = FALSE; // Only update entity view displays where Layout Builder is enabled. if ($display instanceof LayoutEntityDisplayInterface && $display->isLayoutBuilderEnabled()) { foreach ($display->getSections() as $section) { // Add an empty context mapping to each section where one doesn't exist. $section->setLayoutSettings($section->getLayoutSettings() + [ 'context_mapping' => [], ]); // Flag this display as needing to be updated. $needs_update = TRUE; } } return $needs_update; }; $config_entity_updater->update($sandbox, 'entity_view_display', $callback); }