diff --git a/core/modules/layout_builder/config/schema/layout_builder.schema.yml b/core/modules/layout_builder/config/schema/layout_builder.schema.yml index 61768f063a..e6671ad217 100644 --- a/core/modules/layout_builder/config/schema/layout_builder.schema.yml +++ b/core/modules/layout_builder/config/schema/layout_builder.schema.yml @@ -2,9 +2,9 @@ core.entity_view_display.*.*.*.third_party.layout_builder: type: mapping label: 'Per-view-mode Layout Builder settings' mapping: - enable_defaults: + is_active: type: boolean - label: 'Enable the Layout Builder for this display' + label: 'Whether the Layout Builder is active for this display' allow_custom: type: boolean label: 'Allow a customized layout' diff --git a/core/modules/layout_builder/layout_builder.install b/core/modules/layout_builder/layout_builder.install index ccb929a69b..5c07bdb2e4 100644 --- a/core/modules/layout_builder/layout_builder.install +++ b/core/modules/layout_builder/layout_builder.install @@ -24,7 +24,7 @@ function layout_builder_install() { $field_layout += ['settings' => []]; $display ->appendSection(new Section($field_layout['id'], $field_layout['settings'])) - ->setEnabled() + ->activate() ->save(); $display_changed = TRUE; } diff --git a/core/modules/layout_builder/layout_builder.post_update.php b/core/modules/layout_builder/layout_builder.post_update.php index 11a21d4115..32a668fe94 100644 --- a/core/modules/layout_builder/layout_builder.post_update.php +++ b/core/modules/layout_builder/layout_builder.post_update.php @@ -29,13 +29,13 @@ function layout_builder_post_update_rebuild_plugin_dependencies(&$sandbox = NULL } /** - * Mark existing entity displays as enabled. + * Activate Layout Builder for existing entity displays. */ -function layout_builder_post_update_enable_for_existing(&$sandbox = NULL) { +function layout_builder_post_update_activate_existing(&$sandbox = NULL) { $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class); $config_entity_updater->update($sandbox, 'entity_view_display', function (LayoutEntityDisplayInterface $display) { if ($display->getThirdPartySettings('layout_builder')) { - $display->setEnabled(); + $display->activate(); return TRUE; } return FALSE; diff --git a/core/modules/layout_builder/layout_builder.routing.yml b/core/modules/layout_builder/layout_builder.routing.yml index 8d3627b466..125210e579 100644 --- a/core/modules/layout_builder/layout_builder.routing.yml +++ b/core/modules/layout_builder/layout_builder.routing.yml @@ -4,7 +4,7 @@ layout_builder.choose_section: _controller: '\Drupal\layout_builder\Controller\ChooseSectionController::build' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -17,7 +17,7 @@ layout_builder.add_section: _controller: '\Drupal\layout_builder\Controller\AddSectionController::build' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -34,7 +34,7 @@ layout_builder.configure_section: plugin_id: null requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -47,7 +47,7 @@ layout_builder.remove_section: _form: '\Drupal\layout_builder\Form\RemoveSectionForm' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -60,7 +60,7 @@ layout_builder.choose_block: _controller: '\Drupal\layout_builder\Controller\ChooseBlockController::build' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -73,7 +73,7 @@ layout_builder.add_block: _form: '\Drupal\layout_builder\Form\AddBlockForm' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -86,7 +86,7 @@ layout_builder.update_block: _form: '\Drupal\layout_builder\Form\UpdateBlockForm' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -99,7 +99,7 @@ layout_builder.remove_block: _form: '\Drupal\layout_builder\Form\RemoveBlockForm' requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: @@ -118,7 +118,7 @@ layout_builder.move_block: preceding_block_uuid: null requirements: _permission: 'configure any layout' - _layout_defaults_enabled: 'true' + _layout_defaults_active: 'true' options: _admin_route: TRUE parameters: diff --git a/core/modules/layout_builder/layout_builder.services.yml b/core/modules/layout_builder/layout_builder.services.yml index 21a8e8f366..bb2795421f 100644 --- a/core/modules/layout_builder/layout_builder.services.yml +++ b/core/modules/layout_builder/layout_builder.services.yml @@ -2,10 +2,10 @@ services: layout_builder.tempstore_repository: class: Drupal\layout_builder\LayoutTempstoreRepository arguments: ['@tempstore.shared'] - access_check.entity.layout_defaults_enabled: - class: Drupal\layout_builder\Access\LayoutDefaultsEnabledAccessCheck + access_check.entity.layout_defaults_active: + class: Drupal\layout_builder\Access\LayoutDefaultsActiveAccessCheck tags: - - { name: access_check, applies_to: _layout_defaults_enabled } + - { name: access_check, applies_to: _layout_defaults_active } access_check.entity.layout: class: Drupal\layout_builder\Access\LayoutSectionAccessCheck tags: diff --git a/core/modules/layout_builder/src/Access/LayoutDefaultsEnabledAccessCheck.php b/core/modules/layout_builder/src/Access/LayoutDefaultsActiveAccessCheck.php similarity index 94% rename from core/modules/layout_builder/src/Access/LayoutDefaultsEnabledAccessCheck.php rename to core/modules/layout_builder/src/Access/LayoutDefaultsActiveAccessCheck.php index d06cbc90c9..59ce928077 100644 --- a/core/modules/layout_builder/src/Access/LayoutDefaultsEnabledAccessCheck.php +++ b/core/modules/layout_builder/src/Access/LayoutDefaultsActiveAccessCheck.php @@ -13,7 +13,7 @@ * * @internal */ -class LayoutDefaultsEnabledAccessCheck implements AccessInterface { +class LayoutDefaultsActiveAccessCheck implements AccessInterface { /** * Checks routing access to the layout. @@ -33,7 +33,7 @@ public function access(SectionStorageInterface $section_storage) { $defaults_section_storage = $section_storage->getDefaultSectionStorage(); } if ($defaults_section_storage) { - $access = AccessResult::allowedIf($defaults_section_storage->isEnabled()); + $access = AccessResult::allowedIf($defaults_section_storage->isActive()); $access->addCacheableDependency($defaults_section_storage); } else { diff --git a/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php b/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php index 3c3bc25c40..73600e29e8 100644 --- a/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php +++ b/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php @@ -11,8 +11,8 @@ * Determines whether Layout Builder is active for a given entity type or not. * * Cache context ID: 'layout_builder_is_active:%entity_type_id', e.g. - * 'layout_builder_is_active:node' (to vary by whether the Node entity type has - * Layout Builder enabled). + * 'layout_builder_is_active:node' (to vary by whether Layout Builder is active + * for the Node entity type). */ class LayoutBuilderIsActiveCacheContext implements CalculatedCacheContextInterface { diff --git a/core/modules/layout_builder/src/DefaultsSectionStorageInterface.php b/core/modules/layout_builder/src/DefaultsSectionStorageInterface.php index 7a42a57b5e..88ab705745 100644 --- a/core/modules/layout_builder/src/DefaultsSectionStorageInterface.php +++ b/core/modules/layout_builder/src/DefaultsSectionStorageInterface.php @@ -33,21 +33,25 @@ public function isOverridable(); public function setOverridable($overridable = TRUE); /** - * Determines if Layout Builder is enabled for the defaults. + * Determines if Layout Builder is active for the defaults. * * @return bool - * TRUE if Layout Builder is enabled, FALSE otherwise. + * TRUE if Layout Builder is active, FALSE otherwise. */ - public function isEnabled(); + public function isActive(); /** - * Enables the Layout Builder for the defaults. + * Activates the Layout Builder for the defaults. * - * @param bool $enabled - * TRUE if Layout Builder should be enabled, FALSE otherwise. + * @return $this + */ + public function activate(); + + /** + * Deactivates the Layout Builder for the defaults. * * @return $this */ - public function setEnabled($enabled = TRUE); + public function deactivate(); } diff --git a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php index d9a62e9987..e7ca3244fb 100644 --- a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php @@ -38,7 +38,7 @@ public function isOverridable() { */ public function setOverridable($overridable = TRUE) { if ($overridable) { - $this->setEnabled(); + $this->activate(); } $this->setThirdPartySetting('layout_builder', 'allow_custom', $overridable); return $this; @@ -47,36 +47,39 @@ public function setOverridable($overridable = TRUE) { /** * {@inheritdoc} */ - public function isEnabled() { - return (bool) $this->getThirdPartySetting('layout_builder', 'enable_defaults'); + public function isActive() { + return (bool) $this->getThirdPartySetting('layout_builder', 'is_active'); } /** * {@inheritdoc} */ - public function setEnabled($enabled = TRUE) { - $already_enabled = $this->isEnabled(); - $this->setThirdPartySetting('layout_builder', 'enable_defaults', $enabled); - - // Only continue if the state is changing. - if ($already_enabled !== $enabled) { - // If Layout Builder is not already enabled and is being enabled, process - // the existing field formatters. - if ($enabled) { - // Sort the components by weight. - $components = $this->getComponents(); - uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); - foreach ($components as $name => $component) { - $this->setComponent($name, $component); - } + public function activate() { + // If Layout Builder is being activated, process the existing formatters. + if (!$this->isActive()) { + // Sort the components by weight. + $components = $this->getComponents(); + uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); + foreach ($components as $name => $component) { + $this->setComponent($name, $component); } - // If Layout Builder is being disabled, remove all existing section data. - else { - while ($this->count()) { - $this->removeSection(0); - } + } + + $this->setThirdPartySetting('layout_builder', 'is_active', TRUE); + return $this; + } + + /** + * {@inheritdoc} + */ + public function deactivate() { + // If Layout Builder is being deactivated, remove all existing section data. + if ($this->isActive()) { + while ($this->count()) { + $this->removeSection(0); } } + $this->setThirdPartySetting('layout_builder', 'is_active', FALSE); return $this; } @@ -175,7 +178,7 @@ protected function contextRepository() { */ public function buildMultiple(array $entities) { $build_list = parent::buildMultiple($entities); - if (!$this->isEnabled()) { + if (!$this->isActive()) { return $build_list; } diff --git a/core/modules/layout_builder/src/Entity/LayoutEntityDisplayInterface.php b/core/modules/layout_builder/src/Entity/LayoutEntityDisplayInterface.php index c05f1f95a9..174427a5ff 100644 --- a/core/modules/layout_builder/src/Entity/LayoutEntityDisplayInterface.php +++ b/core/modules/layout_builder/src/Entity/LayoutEntityDisplayInterface.php @@ -34,21 +34,25 @@ public function isOverridable(); public function setOverridable($overridable = TRUE); /** - * Determines if Layout Builder is enabled for this display. + * Determines if Layout Builder is active for this display. * * @return bool - * TRUE if Layout Builder is enabled, FALSE otherwise. + * TRUE if Layout Builder is active, FALSE otherwise. */ - public function isEnabled(); + public function isActive(); /** - * Enables the Layout Builder for this display. + * Activates the Layout Builder for this display. * - * @param bool $enabled - * (optional) TRUE if Layout Builder should be enabled, FALSE otherwise. + * @return $this + */ + public function activate(); + + /** + * Deactivates the Layout Builder for this display. * * @return $this */ - public function setEnabled($enabled = TRUE); + public function deactivate(); } diff --git a/core/modules/layout_builder/src/Form/LayoutBuilderDeactivateForm.php b/core/modules/layout_builder/src/Form/LayoutBuilderDeactivateForm.php new file mode 100644 index 0000000000..38cc5c355e --- /dev/null +++ b/core/modules/layout_builder/src/Form/LayoutBuilderDeactivateForm.php @@ -0,0 +1,113 @@ +layoutTempstoreRepository = $layout_tempstore_repository; + $this->messenger = $messenger; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('layout_builder.tempstore_repository'), + $container->get('messenger') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'layout_builder_deactivate_form'; + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return $this->t('Are you sure you want to deactivate Layout Builder?'); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('All customizations will be removed. This action cannot be undone.'); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return $this->sectionStorage->getRedirectUrl(); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) { + if (!$section_storage instanceof DefaultsSectionStorageInterface) { + throw new \InvalidArgumentException(sprintf('The section storage with type "%s" and ID "%s" does not provide defaults', $section_storage->getStorageType(), $section_storage->getStorageId())); + } + + $this->sectionStorage = $section_storage; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->sectionStorage->deactivate()->save(); + $this->layoutTempstoreRepository->delete($this->sectionStorage); + + $this->messenger()->addMessage($this->t('Layout Builder has been deactivated.')); + $form_state->setRedirectUrl($this->getCancelUrl()); + } + +} diff --git a/core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php b/core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php index ba224e363d..40a57d9bf3 100644 --- a/core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php +++ b/core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php @@ -28,7 +28,7 @@ class LayoutBuilderEntityViewDisplayForm extends EntityViewDisplayEditForm { /** * The storage section. * - * @var \Drupal\layout_builder\SectionStorageInterface + * @var \Drupal\layout_builder\DefaultsSectionStorageInterface */ protected $sectionStorage; @@ -46,8 +46,8 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $is_enabled = $this->entity->isEnabled(); - if ($is_enabled) { + $is_active = $this->entity->isActive(); + if ($is_active) { // Hide the table of fields. $form['fields']['#access'] = FALSE; $form['#fields'] = []; @@ -66,7 +66,7 @@ public function form(array $form, FormStateInterface $form_state) { '#weight' => -10, '#attributes' => ['class' => ['button']], '#url' => $this->sectionStorage->getLayoutBuilderUrl(), - '#access' => $is_enabled, + '#access' => $is_active, ]; $form['layout'] = [ @@ -76,10 +76,10 @@ public function form(array $form, FormStateInterface $form_state) { '#tree' => TRUE, ]; - $form['layout']['enable_defaults'] = [ + $form['layout']['is_active'] = [ '#type' => 'checkbox', '#title' => $this->t('Use Layout Builder'), - '#default_value' => $is_enabled, + '#default_value' => $is_active, ]; $form['#entity_builders']['layout_builder'] = '::entityFormEntityBuild'; @@ -93,20 +93,20 @@ public function form(array $form, FormStateInterface $form_state) { '@entity' => $entity_type->getSingularLabel(), ]), '#default_value' => $this->entity->isOverridable(), - '#disabled' => !$is_enabled, + '#disabled' => !$is_active, '#states' => [ 'disabled' => [ - ':input[name="layout[enable_defaults]"]' => ['checked' => FALSE], + ':input[name="layout[is_active]"]' => ['checked' => FALSE], ], 'invisible' => [ - ':input[name="layout[enable_defaults]"]' => ['checked' => FALSE], + ':input[name="layout[is_active]"]' => ['checked' => FALSE], ], ], ]; // Prevent turning off overrides while any exist. if ($this->hasOverrides($this->entity)) { - $form['layout']['enable_defaults']['#disabled'] = TRUE; - $form['layout']['enable_defaults']['#description'] = $this->t('You must revert all customized layouts of this display before you can disable this option.'); + $form['layout']['is_active']['#disabled'] = TRUE; + $form['layout']['is_active']['#description'] = $this->t('You must revert all customized layouts of this display before you can disable this option.'); $form['layout']['allow_custom']['#disabled'] = TRUE; $form['layout']['allow_custom']['#description'] = $this->t('You must revert all customized layouts of this display before you can disable this option.'); unset($form['#entity_builders']['layout_builder']); @@ -142,15 +142,24 @@ protected function hasOverrides(LayoutEntityDisplayInterface $display) { * Entity builder for layout options on the entity view display form. */ public function entityFormEntityBuild($entity_type_id, LayoutEntityDisplayInterface $display, &$form, FormStateInterface &$form_state) { - $enable_defaults = (bool) $form_state->getValue(['layout', 'enable_defaults'], FALSE); - $display->setEnabled($enable_defaults); - - if (!$enable_defaults) { - $overridable = FALSE; - } - else { + $set_active = (bool) $form_state->getValue(['layout', 'is_active'], FALSE); + if ($set_active) { $overridable = (bool) $form_state->getValue(['layout', 'allow_custom'], FALSE); } + else { + if ($display->isActive()) { + $form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl('deactivate')); + return; + } + $overridable = FALSE; + } + + if ($set_active) { + $display->activate(); + } + else { + $display->deactivate(); + } $display->setOverridable($overridable); } @@ -158,7 +167,7 @@ public function entityFormEntityBuild($entity_type_id, LayoutEntityDisplayInterf * {@inheritdoc} */ protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { - if (!$this->entity->isEnabled() && $field_definition->getType() !== 'layout_section') { + if (!$this->entity->isActive() && $field_definition->getType() !== 'layout_section') { return parent::buildFieldRow($field_definition, $form, $form_state); } } @@ -167,7 +176,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, arr * {@inheritdoc} */ protected function buildExtraFieldRow($field_id, $extra_field) { - if (!$this->entity->isEnabled()) { + if (!$this->entity->isActive()) { return parent::buildExtraFieldRow($field_id, $extra_field); } } diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php index 48279a81ac..70f23457ac 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php @@ -125,8 +125,8 @@ public function getRedirectUrl() { /** * {@inheritdoc} */ - public function getLayoutBuilderUrl() { - return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getDisplay()->getTargetEntityTypeId()}.view", $this->getRouteParameters()); + public function getLayoutBuilderUrl($rel = 'view') { + return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getDisplay()->getTargetEntityTypeId()}.$rel", $this->getRouteParameters()); } /** @@ -296,15 +296,23 @@ public function setOverridable($overridable = TRUE) { /** * {@inheritdoc} */ - public function isEnabled() { - return $this->getDisplay()->isEnabled(); + public function isActive() { + return $this->getDisplay()->isActive(); } /** * {@inheritdoc} */ - public function setEnabled($enabled = TRUE) { - $this->getDisplay()->setEnabled($enabled); + public function activate() { + $this->getDisplay()->activate(); + return $this; + } + + /** + * {@inheritdoc} + */ + public function deactivate() { + $this->getDisplay()->deactivate(); return $this; } diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php index db38b1203e..dd7931d7de 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php @@ -202,10 +202,10 @@ public function getRedirectUrl() { /** * {@inheritdoc} */ - public function getLayoutBuilderUrl() { + public function getLayoutBuilderUrl($rel = 'view') { $entity = $this->getEntity(); $route_parameters[$entity->getEntityTypeId()] = $entity->id(); - return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getEntity()->getEntityTypeId()}.view", $route_parameters); + return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getEntity()->getEntityTypeId()}.$rel", $route_parameters); } /** diff --git a/core/modules/layout_builder/src/Routing/LayoutBuilderRoutesTrait.php b/core/modules/layout_builder/src/Routing/LayoutBuilderRoutesTrait.php index 12c6d9f6d6..556b734ff5 100644 --- a/core/modules/layout_builder/src/Routing/LayoutBuilderRoutesTrait.php +++ b/core/modules/layout_builder/src/Routing/LayoutBuilderRoutesTrait.php @@ -3,6 +3,7 @@ namespace Drupal\layout_builder\Routing; use Drupal\Component\Utility\NestedArray; +use Drupal\layout_builder\DefaultsSectionStorageInterface; use Drupal\layout_builder\OverridesSectionStorageInterface; use Drupal\layout_builder\SectionStorage\SectionStorageDefinition; use Symfony\Component\Routing\Route; @@ -43,7 +44,7 @@ protected function buildLayoutRoutes(RouteCollection $collection, SectionStorage $defaults['section_storage'] = ''; // Trigger the layout builder access check. $requirements['_has_layout_section'] = 'true'; - $requirements['_layout_defaults_enabled'] = 'true'; + $requirements['_layout_defaults_active'] = 'true'; // Trigger the layout builder RouteEnhancer. $options['_layout_builder'] = TRUE; // Trigger the layout builder param converter. @@ -93,6 +94,17 @@ protected function buildLayoutRoutes(RouteCollection $collection, SectionStorage ->setOptions($options); $collection->add("$route_name_prefix.revert", $route); } + elseif (is_subclass_of($definition->getClass(), DefaultsSectionStorageInterface::class)) { + $deactivate_defaults = $defaults; + $deactivate_defaults['_form'] = '\Drupal\layout_builder\Form\LayoutBuilderDeactivateForm'; + $deactivate_options = $options; + unset($deactivate_options['_admin_route'], $deactivate_options['_layout_builder']); + $route = (new Route("$path/deactivate")) + ->setDefaults($deactivate_defaults) + ->setRequirements($requirements) + ->setOptions($deactivate_options); + $collection->add("$route_name_prefix.deactivate", $route); + } } } diff --git a/core/modules/layout_builder/src/SectionStorageInterface.php b/core/modules/layout_builder/src/SectionStorageInterface.php index e7fbb086b8..282a819721 100644 --- a/core/modules/layout_builder/src/SectionStorageInterface.php +++ b/core/modules/layout_builder/src/SectionStorageInterface.php @@ -88,10 +88,13 @@ public function getRedirectUrl(); /** * Gets the URL used to display the Layout Builder UI. * + * @param string $rel + * The link relationship type, for example: view or deactivate. + * * @return \Drupal\Core\Url * The URL object. */ - public function getLayoutBuilderUrl(); + public function getLayoutBuilderUrl($rel = 'view'); /** * Configures the plugin based on route values. diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderOptInTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderOptInTest.php index 808e5388c9..d643d5ce17 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderOptInTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderOptInTest.php @@ -52,12 +52,12 @@ public function testDefaultValues() { // Both the content type created before and after Layout Builder was // installed is still using the Field UI. $this->drupalGet('admin/structure/types/manage/before/display/default'); - $assert_session->checkboxNotChecked('layout[enable_defaults]'); + $assert_session->checkboxNotChecked('layout[is_active]'); $field_ui_prefix = 'admin/structure/types/manage/after/display/default'; $this->drupalGet($field_ui_prefix); - $assert_session->checkboxNotChecked('layout[enable_defaults]'); - $page->checkField('layout[enable_defaults]'); + $assert_session->checkboxNotChecked('layout[is_active]'); + $page->checkField('layout[is_active]'); $page->pressButton('Save'); $layout_builder_ui = $this->getPathForFieldBlock('node', 'after', 'default', 'body'); @@ -72,12 +72,14 @@ public function testDefaultValues() { $page->pressButton('Update'); $assert_session->linkExists('Save Layout'); $this->clickLink('Save Layout'); - $this->htmlOutput($page->getContent()); + $this->drupalGet($layout_builder_ui); $assert_session->fieldValueEquals('settings[formatter][type]', 'text_trimmed'); - // Disable Layout Builder. - $this->drupalPostForm($field_ui_prefix, ['layout[enable_defaults]' => FALSE], 'Save'); + // Deactivate Layout Builder. + $this->drupalPostForm($field_ui_prefix, ['layout[is_active]' => FALSE], 'Save'); + $page->pressButton('Confirm'); + // The Layout Builder UI is no longer accessible. $this->drupalGet($layout_builder_ui); $assert_session->statusCodeEquals(403); @@ -91,8 +93,8 @@ public function testDefaultValues() { $page->pressButton('Save'); $assert_session->fieldValueEquals('fields[body][type]', 'text_summary_or_trimmed'); - // Reenable Layout Builder. - $this->drupalPostForm($field_ui_prefix, ['layout[enable_defaults]' => TRUE], 'Save'); + // Reactivate Layout Builder. + $this->drupalPostForm($field_ui_prefix, ['layout[is_active]' => TRUE], 'Save'); // The changed body formatter is reflected in Layout Builder UI. $this->drupalGet($this->getPathForFieldBlock('node', 'after', 'default', 'body')); $assert_session->fieldValueEquals('settings[formatter][type]', 'text_summary_or_trimmed'); diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index ea4dec7041..574a39e575 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -83,7 +83,7 @@ public function testLayoutBuilderUi() { $assert_session->linkNotExists('Manage layout'); $assert_session->fieldDisabled('layout[allow_custom]'); - $this->drupalPostForm(NULL, ['layout[enable_defaults]' => TRUE], 'Save'); + $this->drupalPostForm(NULL, ['layout[is_active]' => TRUE], 'Save'); $assert_session->linkExists('Manage layout'); $this->clickLink('Manage layout'); $assert_session->addressEquals("$field_ui_prefix/display-layout/default"); @@ -221,7 +221,7 @@ public function testPluginDependencies() { $page->fillField('id', 'myothermenu'); $page->pressButton('Save'); - $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display', ['layout[enable_defaults]' => TRUE], 'Save'); + $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display', ['layout[is_active]' => TRUE], 'Save'); $assert_session->linkExists('Manage layout'); $this->clickLink('Manage layout'); $assert_session->linkExists('Add Section'); @@ -285,7 +285,7 @@ public function testLayoutBuilderUiFullViewMode() { $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field'; // Allow overrides for the layout. - $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[enable_defaults]' => TRUE], 'Save'); + $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[is_active]' => TRUE], 'Save'); $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => TRUE], 'Save'); // Customize the default view mode. @@ -346,7 +346,7 @@ public function testLayoutBuilderChooseBlocksAlter() { ])); // From the manage display page, go to manage the layout. - $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enable_defaults]' => TRUE], 'Save'); + $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[is_active]' => TRUE], 'Save'); $assert_session->linkExists('Manage layout'); $this->clickLink('Manage layout'); @@ -376,7 +376,7 @@ public function testDeletedView() { $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field'; // Enable overrides. - $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[enable_defaults]' => TRUE], 'Save'); + $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[is_active]' => TRUE], 'Save'); $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => TRUE], 'Save'); $this->drupalGet('node/1'); diff --git a/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderCompatibilityTestBase.php b/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderCompatibilityTestBase.php index df702ae909..e3868dbff0 100644 --- a/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderCompatibilityTestBase.php +++ b/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderCompatibilityTestBase.php @@ -91,6 +91,7 @@ protected function setUp() { protected function installLayoutBuilder() { $this->container->get('module_installer')->install(['layout_builder']); $this->refreshServices(); + $this->display = $this->reloadEntity($this->display); } diff --git a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php index c554f659a5..8347da33cd 100644 --- a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php @@ -254,7 +254,7 @@ public function testBuildRoutes() { [ '_field_ui_view_mode_access' => 'administer with_bundle_key display', '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -276,7 +276,7 @@ public function testBuildRoutes() { [ '_field_ui_view_mode_access' => 'administer with_bundle_key display', '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -298,7 +298,7 @@ public function testBuildRoutes() { [ '_field_ui_view_mode_access' => 'administer with_bundle_key display', '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -308,6 +308,26 @@ public function testBuildRoutes() { '_admin_route' => FALSE, ] ), + 'layout_builder.defaults.with_bundle_key.deactivate' => new Route( + '/admin/entity/whatever/display-layout/{view_mode_name}/deactivate', + [ + 'entity_type_id' => 'with_bundle_key', + 'bundle_key' => 'my_bundle_type', + 'section_storage_type' => 'defaults', + 'section_storage' => '', + '_form' => '\Drupal\layout_builder\Form\LayoutBuilderDeactivateForm', + ], + [ + '_field_ui_view_mode_access' => 'administer with_bundle_key display', + '_has_layout_section' => 'true', + '_layout_defaults_active' => 'true', + ], + [ + 'parameters' => [ + 'section_storage' => ['layout_builder_tempstore' => TRUE], + ], + ] + ), 'layout_builder.defaults.with_bundle_parameter.view' => new Route( '/admin/entity/{bundle}/display-layout/{view_mode_name}', [ @@ -321,7 +341,7 @@ public function testBuildRoutes() { [ '_field_ui_view_mode_access' => 'administer with_bundle_parameter display', '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -342,7 +362,7 @@ public function testBuildRoutes() { [ '_field_ui_view_mode_access' => 'administer with_bundle_parameter display', '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -363,7 +383,7 @@ public function testBuildRoutes() { [ '_field_ui_view_mode_access' => 'administer with_bundle_parameter display', '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -373,6 +393,25 @@ public function testBuildRoutes() { '_admin_route' => FALSE, ] ), + 'layout_builder.defaults.with_bundle_parameter.deactivate' => new Route( + '/admin/entity/{bundle}/display-layout/{view_mode_name}/deactivate', + [ + 'entity_type_id' => 'with_bundle_parameter', + 'section_storage_type' => 'defaults', + 'section_storage' => '', + '_form' => '\Drupal\layout_builder\Form\LayoutBuilderDeactivateForm', + ], + [ + '_field_ui_view_mode_access' => 'administer with_bundle_parameter display', + '_has_layout_section' => 'true', + '_layout_defaults_active' => 'true', + ], + [ + 'parameters' => [ + 'section_storage' => ['layout_builder_tempstore' => TRUE], + ], + ] + ), ]; $collection = new RouteCollection(); diff --git a/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php index 4619a239d5..d1242d5617 100644 --- a/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php @@ -223,7 +223,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -243,7 +243,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -263,7 +263,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -283,7 +283,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', ], [ 'parameters' => [ @@ -305,7 +305,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', 'with_integer_id' => '\d+', ], [ @@ -326,7 +326,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', 'with_integer_id' => '\d+', ], [ @@ -347,7 +347,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', 'with_integer_id' => '\d+', ], [ @@ -368,7 +368,7 @@ public function testBuildRoutes() { ], [ '_has_layout_section' => 'true', - '_layout_defaults_enabled' => 'true', + '_layout_defaults_active' => 'true', 'with_integer_id' => '\d+', ], [