trait EnableLayoutBuilderTrait
Same name in other branches
- 11.x core/modules/layout_builder/tests/src/Traits/EnableLayoutBuilderTrait.php \Drupal\Tests\layout_builder\Traits\EnableLayoutBuilderTrait
Test trait to enable or disable Layout Builder on an entity view display.
Hierarchy
- trait \Drupal\Tests\layout_builder\Traits\EnableLayoutBuilderTrait
5 files declare their use of EnableLayoutBuilderTrait
- LayoutBuilderOptInTest.php in core/
modules/ layout_builder/ tests/ src/ FunctionalJavascript/ LayoutBuilderOptInTest.php - LayoutBuilderOverridesEditingThemeTest.php in core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderOverridesEditingThemeTest.php - LayoutBuilderTest.php in core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderTest.php - LayoutBuilderViewModeTest.php in core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderViewModeTest.php - LayoutDisplayTest.php in core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutDisplayTest.php
File
-
core/
modules/ layout_builder/ tests/ src/ Traits/ EnableLayoutBuilderTrait.php, line 12
Namespace
Drupal\Tests\layout_builder\TraitsView source
trait EnableLayoutBuilderTrait {
/**
* Enables Layout Builder on an entity view display.
*
* @param \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display
* The entity view display.
*/
protected function enableLayoutBuilder(LayoutEntityDisplayInterface $display) : void {
$display->enableLayoutBuilder()
->setOverridable()
->save();
}
/**
* Enables Layout Builder using the UI.
*
* @param string $bundle
* The bundle that Layout Builder is being enabled on.
* @param string $viewMode
* The view mode that Layout Builder is being enabled on.
* @param bool $allowCustom
* Whether custom layouts per entity should be allowed.
*/
protected function enableLayoutBuilderFromUi(string $bundle, string $viewMode, bool $allowCustom = TRUE) : void {
$path = sprintf('admin/structure/types/manage/%s/display/%s', $bundle, $viewMode);
$page = $this->getSession()
->getPage();
$this->drupalGet($path);
$page->checkField('layout[enabled]');
$page->pressButton('Save');
if ($allowCustom) {
$page->checkField('layout[allow_custom]');
$page->pressButton('Save');
}
}
/**
* Disables Layout Builder using the UI.
*
* @param string $bundle
* The bundle that Layout Builder is being disabled on.
* @param string $viewMode
* The view mode that Layout Builder is being disabled on.
*/
protected function disableLayoutBuilderFromUi(string $bundle, string $viewMode) : void {
$path = sprintf('admin/structure/types/manage/%s/display/%s', $bundle, $viewMode);
$page = $this->getSession()
->getPage();
$this->drupalGet($path);
$page->uncheckField('layout[enabled]');
$page->pressButton('Save');
$page->pressButton('Confirm');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
EnableLayoutBuilderTrait::disableLayoutBuilderFromUi | protected | function | Disables Layout Builder using the UI. |
EnableLayoutBuilderTrait::enableLayoutBuilder | protected | function | Enables Layout Builder on an entity view display. |
EnableLayoutBuilderTrait::enableLayoutBuilderFromUi | protected | function | Enables Layout Builder using the UI. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.