Loading core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +4 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Config\Action\Attribute\ActionMethod; use Drupal\Core\Entity\Entity\EntityViewDisplay as BaseEntityViewDisplay; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\FieldableEntityInterface; Loading Loading @@ -58,6 +59,7 @@ public function isOverridable() { /** * {@inheritdoc} */ #[ActionMethod(adminLabel: new TranslatableMarkup('Toggle overridable layouts'), pluralize: FALSE, name: 'allowLayoutOverrides')] public function setOverridable($overridable = TRUE) { $this->setThirdPartySetting('layout_builder', 'allow_custom', $overridable); // Enable Layout Builder if it's not already enabled and overriding. Loading @@ -82,6 +84,7 @@ public function isLayoutBuilderEnabled() { /** * {@inheritdoc} */ #[ActionMethod(adminLabel: new TranslatableMarkup('Enable Layout Builder'), pluralize: FALSE)] public function enableLayoutBuilder() { $this->setThirdPartySetting('layout_builder', 'enabled', TRUE); return $this; Loading @@ -90,6 +93,7 @@ public function enableLayoutBuilder() { /** * {@inheritdoc} */ #[ActionMethod(adminLabel: new TranslatableMarkup('Disable Layout Builder'), pluralize: FALSE)] public function disableLayoutBuilder() { $this->setOverridable(FALSE); $this->setThirdPartySetting('layout_builder', 'enabled', FALSE); Loading core/modules/layout_builder/tests/src/Kernel/ConfigActionsTest.php 0 → 100644 +58 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\layout_builder\Kernel; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\entity_test\Entity\EntityTestBundle; use Drupal\KernelTests\KernelTestBase; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; /** * @group Recipe */ class ConfigActionsTest extends KernelTestBase { /** * {@inheritdoc} */ protected static $modules = [ 'entity_test', 'field', 'layout_builder', 'layout_discovery', ]; /** * Tests config actions exposed by Layout Builder. */ public function testLayoutBuilderActions(): void { /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */ $manager = $this->container->get('plugin.manager.config_action'); EntityTestBundle::create(['id' => 'test'])->save(); /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ $display_repository = $this->container->get(EntityDisplayRepositoryInterface::class); /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $display */ $display = $display_repository->getViewDisplay('entity_test_with_bundle', 'test'); $this->assertInstanceOf(LayoutBuilderEntityViewDisplay::class, $display); $display->save(); $this->assertFalse($display->isLayoutBuilderEnabled()); $manager->applyAction('enableLayoutBuilder', $display->getConfigDependencyName(), []); $this->assertTrue($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isLayoutBuilderEnabled()); $this->assertFalse($display->isOverridable()); $manager->applyAction('allowLayoutOverrides', $display->getConfigDependencyName(), TRUE); $this->assertTrue($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isOverridable()); $manager->applyAction('allowLayoutOverrides', $display->getConfigDependencyName(), FALSE); $this->assertFalse($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isOverridable()); $manager->applyAction('disableLayoutBuilder', $display->getConfigDependencyName(), []); $this->assertFalse($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isLayoutBuilderEnabled()); } } Loading
core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +4 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Config\Action\Attribute\ActionMethod; use Drupal\Core\Entity\Entity\EntityViewDisplay as BaseEntityViewDisplay; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\FieldableEntityInterface; Loading Loading @@ -58,6 +59,7 @@ public function isOverridable() { /** * {@inheritdoc} */ #[ActionMethod(adminLabel: new TranslatableMarkup('Toggle overridable layouts'), pluralize: FALSE, name: 'allowLayoutOverrides')] public function setOverridable($overridable = TRUE) { $this->setThirdPartySetting('layout_builder', 'allow_custom', $overridable); // Enable Layout Builder if it's not already enabled and overriding. Loading @@ -82,6 +84,7 @@ public function isLayoutBuilderEnabled() { /** * {@inheritdoc} */ #[ActionMethod(adminLabel: new TranslatableMarkup('Enable Layout Builder'), pluralize: FALSE)] public function enableLayoutBuilder() { $this->setThirdPartySetting('layout_builder', 'enabled', TRUE); return $this; Loading @@ -90,6 +93,7 @@ public function enableLayoutBuilder() { /** * {@inheritdoc} */ #[ActionMethod(adminLabel: new TranslatableMarkup('Disable Layout Builder'), pluralize: FALSE)] public function disableLayoutBuilder() { $this->setOverridable(FALSE); $this->setThirdPartySetting('layout_builder', 'enabled', FALSE); Loading
core/modules/layout_builder/tests/src/Kernel/ConfigActionsTest.php 0 → 100644 +58 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\layout_builder\Kernel; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\entity_test\Entity\EntityTestBundle; use Drupal\KernelTests\KernelTestBase; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; /** * @group Recipe */ class ConfigActionsTest extends KernelTestBase { /** * {@inheritdoc} */ protected static $modules = [ 'entity_test', 'field', 'layout_builder', 'layout_discovery', ]; /** * Tests config actions exposed by Layout Builder. */ public function testLayoutBuilderActions(): void { /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */ $manager = $this->container->get('plugin.manager.config_action'); EntityTestBundle::create(['id' => 'test'])->save(); /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ $display_repository = $this->container->get(EntityDisplayRepositoryInterface::class); /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $display */ $display = $display_repository->getViewDisplay('entity_test_with_bundle', 'test'); $this->assertInstanceOf(LayoutBuilderEntityViewDisplay::class, $display); $display->save(); $this->assertFalse($display->isLayoutBuilderEnabled()); $manager->applyAction('enableLayoutBuilder', $display->getConfigDependencyName(), []); $this->assertTrue($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isLayoutBuilderEnabled()); $this->assertFalse($display->isOverridable()); $manager->applyAction('allowLayoutOverrides', $display->getConfigDependencyName(), TRUE); $this->assertTrue($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isOverridable()); $manager->applyAction('allowLayoutOverrides', $display->getConfigDependencyName(), FALSE); $this->assertFalse($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isOverridable()); $manager->applyAction('disableLayoutBuilder', $display->getConfigDependencyName(), []); $this->assertFalse($display_repository->getViewDisplay('entity_test_with_bundle', 'test')->isLayoutBuilderEnabled()); } }