Skip to content
Snippets Groups Projects
Unverified Commit 6d5a320d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3486981 by phenaproxima, thejimbirch: Allow recipes to enable Layout...

Issue #3486981 by phenaproxima, thejimbirch: Allow recipes to enable Layout Builder via config actions

(cherry picked from commit 524cf737)
parent 88b2e375
No related branches found
No related tags found
23 merge requests!11636Draft: Issue #3515643 by macsim: fieldNameExists method is inconsistent,!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator,!10570Issue #3494197: Convert Twig engine hooks,!10567Issue #3494154: Index is not added if entity doesn't support revisions,!10548Revert "Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing",!10404Margin has been added,!10391Issue #3485117 by nexusnovaz, godotislate, nicxvan: Fix return type on...,!10388Issue #3485117 by nexusnovaz, godotislate, nicxvan: Fix return type on...,!10376Issue #3485117 by nexusnovaz, godotislate, nicxvan: Fix return type on...,!10237Issue #3484105 by nicxvan, godotislate: Automatically included .inc files are no longer included
Pipeline #339297 canceled
Pipeline: drupal

#339298

    ......@@ -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;
    ......@@ -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.
    ......@@ -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;
    ......@@ -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);
    ......
    <?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());
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment