diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 60fa71d6af..cf800783e1 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -376,14 +376,16 @@ public function getPluginCollections() { * {@inheritdoc} */ public function setLayoutId($layout_id, array $layout_settings = []) { - return $this->entityManager->setLayoutId($layout_id, $layout_settings); + // @todo Not clear the purpose. + return $this->setLayoutFromId($layout_id, $layout_settings); } /** * {@inheritdoc} */ - public function ensureLayout($layout_id = 'layout_onecol') { - return $this->entityManager->ensureLayout($layout_id); + public function ensureLayout($default_layout_id = 'layout_onecol') { + // @todo Not clear the purpose. + return $this->layout_id = $default_layout_id; } } diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 128c1a1139..5ce8d11aed 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -379,14 +379,16 @@ public function getPluginCollections() { * {@inheritdoc} */ public function setLayoutId($layout_id, array $layout_settings = []) { - return $this->entityManager->setLayoutId($layout_id, $layout_settings); + // @todo Not clear the purpose. + return $this->setLayoutFromId($layout_id, $layout_settings); } /** * {@inheritdoc} */ - public function ensureLayout($layout_id = 'layout_onecol') { - return $this->entityManager->ensureLayout($layout_id); + public function ensureLayout($default_layout_id = 'layout_onecol') { + // @todo Not clear the purpose. + return $this->layout_id = $default_layout_id; } } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index ff59380ac8..da9260d2c2 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -186,7 +186,6 @@ public function __construct(array $values, $entity_type) { protected function init() { // Only populate defaults for "official" view modes and form modes. if ($this->mode !== static::CUSTOM_MODE) { - $default_region = $this->getDefaultRegion(); // Fill in defaults for extra fields. $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; $extra_fields = \Drupal::service('entity_field.manager')->getExtraFields($this->targetEntityType, $this->bundle); @@ -635,6 +634,7 @@ public function setLayoutFromId($layout_id, array $layout_settings = []) { $original_layout_id = $this->getLayoutId(); $this->layout_id = $layout_id; $this->getPluginCollection()->addInstanceID($layout_id, $layout_settings); + $this->layout_settings = $this->getPluginCollection()->getConfiguration(); if ($original_layout_id !== $layout_id) { // @todo Devise a mechanism for mapping old regions to new ones in diff --git a/core/lib/Drupal/Core/Layout/Annotation/Layout.php b/core/lib/Drupal/Core/Layout/Annotation/Layout.php index 371c1af3c8..8aaff51d6b 100644 --- a/core/lib/Drupal/Core/Layout/Annotation/Layout.php +++ b/core/lib/Drupal/Core/Layout/Annotation/Layout.php @@ -40,7 +40,9 @@ class Layout extends Plugin { public $label; /** - * An optional description for advanced layouts. + * A description for advanced layouts. + * + * This property is optional and it does not need to be declared. * * Sometimes layouts are so complex that the name is insufficient to describe * a layout such that a visually impaired administrator could layout a page @@ -71,7 +73,9 @@ class Layout extends Plugin { * hook_theme() and the module or theme registering this layout does not need * to do it. * - * @var string optional + * This property is optional and it does not need to be declared. + * + * @var string * * @see hook_theme() */ @@ -80,11 +84,13 @@ class Layout extends Plugin { /** * The theme hook used to render this layout. * + * This property is optional and it does not need to be declared. + * * If specified, it's assumed that the module or theme registering this layout * will also register the theme hook with hook_theme() itself. This is * mutually exclusive with 'template' - you can't specify both. * - * @var string optional + * @var string * * @see hook_theme() */ @@ -93,28 +99,36 @@ class Layout extends Plugin { /** * Path (relative to the module or theme) to resources like icon or template. * - * @var string optional + * This property is optional and it does not need to be declared. + * + * @var string */ public $path; /** * The asset library. * - * @var string optional + * This property is optional and it does not need to be declared. + * + * @var string */ public $library; /** * The path to the preview image (relative to the 'path' given). * - * @var string optional + * This property is optional and it does not need to be declared. + * + * @var string */ public $icon; /** * The icon map. * - * @var string[][] optional + * This property is optional and it does not need to be declared. + * + * @var string[][] * * @see \Drupal\Core\Layout\Icon\IconBuilderInterface::build() */ diff --git a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php index 467114bc72..3d48c67058 100644 --- a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php +++ b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php @@ -18,7 +18,6 @@ class FieldLayoutTest extends WebDriverTestBase { protected static $modules = [ 'field_layout', 'field_ui', - 'field_layout_test', 'layout_test', ]; diff --git a/core/modules/system/tests/modules/layout_test/layout_test.info.yml b/core/modules/system/tests/modules/layout_test/layout_test.info.yml index 8492c1b8bc..fbce7043fa 100644 --- a/core/modules/system/tests/modules/layout_test/layout_test.info.yml +++ b/core/modules/system/tests/modules/layout_test/layout_test.info.yml @@ -4,4 +4,4 @@ description: 'Support module for testing layouts.' package: Testing version: VERSION dependencies: - - entity_test + - drupal:entity_test diff --git a/core/modules/system/tests/modules/layout_test/src/Plugin/Layout/TestLayoutContentFooter.php b/core/modules/system/tests/modules/layout_test/src/Plugin/Layout/TestLayoutContentFooter.php index c283c82d78..62ae00e472 100644 --- a/core/modules/system/tests/modules/layout_test/src/Plugin/Layout/TestLayoutContentFooter.php +++ b/core/modules/system/tests/modules/layout_test/src/Plugin/Layout/TestLayoutContentFooter.php @@ -1,6 +1,6 @@ 'en', 'status' => TRUE, 'dependencies' => [], - 'third_party_settings' => [ - 'field_layout' => [ - 'id' => 'layout_onecol', - 'settings' => [ - 'label' => '', - ], - ], - ], 'id' => 'entity_test.entity_test.default', 'targetEntityType' => 'entity_test', 'bundle' => 'entity_test', @@ -77,9 +70,8 @@ public function testPreSave() { // The dependencies have been updated. $expected['dependencies']['module'] = [ 'entity_test', - 'field_layout', - 'layout_discovery', ]; + $expected['layout_settings']['label'] = ''; // A third party setting is added by the entity_test module. $expected['third_party_settings']['entity_test'] = ['foo' => 'bar']; // The visible field is assigned the default region. @@ -106,6 +98,8 @@ public function testPreSave() { 'settings' => [], 'third_party_settings' => [], ]; + $expected['layout_id'] = 'test_layout_main_and_footer'; + $expected['layout_settings'] = ['setting_1' => 'Default']; $this->assertEntityValues($expected, $entity_display->toArray()); // After saving, the dependencies have been updated. @@ -114,8 +108,7 @@ public function testPreSave() { 'dependency_from_annotation', 'dependency_from_calculateDependencies', 'entity_test', - 'field_layout', - 'field_layout_test', + 'layout_test', ]; $this->assertEntityValues($expected, $entity_display->toArray()); @@ -124,7 +117,7 @@ public function testPreSave() { $entity_display->save(); // The setting overrides the default value. - $expected['third_party_settings']['field_layout']['settings']['setting_1'] = 'foobar'; + $expected['layout_settings']['setting_1'] = 'foobar'; $this->assertEntityValues($expected, $entity_display->toArray()); // Move a field to the non-default region. @@ -145,7 +138,7 @@ public function testPreSave() { $expected['dependencies']['module'] = [ 'entity_test', 'field_layout', - 'field_layout_test', + 'layout_test', ]; // The layout has been updated. $expected['third_party_settings']['field_layout'] = [ diff --git a/core/tests/Drupal/Tests/Core/Entity/Display/EntityFormDisplayTest.php b/core/tests/Drupal/Tests/Core/Entity/Display/EntityFormDisplayTest.php index 6dbda03708..ee08a129ea 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Display/EntityFormDisplayTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Display/EntityFormDisplayTest.php @@ -40,7 +40,7 @@ class EntityFormDisplayTest extends UnitTestCase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->pluginDefinition = new LayoutDefinition([ @@ -171,7 +171,7 @@ public function testApplyLayout() { '#process' => ['\Drupal\Core\Render\Element\RenderElement::processGroup'], '#pre_render' => ['\Drupal\Core\Render\Element\RenderElement::preRenderGroup'], ], - '#settings' => [], + '#settings' => ['label' => ''], '#layout' => $this->pluginDefinition, '#theme' => 'layout__twocol', '#attached' => [ diff --git a/core/tests/Drupal/Tests/Core/Entity/Display/EntityViewDisplayTest.php b/core/tests/Drupal/Tests/Core/Entity/Display/EntityViewDisplayTest.php index 5e9d3d7bdc..81f635ee01 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Display/EntityViewDisplayTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Display/EntityViewDisplayTest.php @@ -39,7 +39,7 @@ class EntityViewDisplayTest extends UnitTestCase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->pluginDefinition = new LayoutDefinition([ @@ -171,7 +171,7 @@ public function testApplyLayout() { '#markup' => 'Configurable', ], ], - '#settings' => [], + '#settings' => ['label' => ''], '#layout' => $this->pluginDefinition, '#theme' => 'layout__twocol', '#attached' => [ @@ -257,7 +257,7 @@ public function testGetFieldFromBuild($field_name, $expected_field_array) { '#markup' => 'Configurable', ], ], - '#settings' => [], + '#settings' => ['label' => ''], '#layout' => $this->pluginDefinition, '#theme' => 'layout__twocol', '#attached' => [ @@ -348,7 +348,7 @@ public function testSetFieldOnBuildUnknownField() { 'entity_view_display' ); - $this->setExpectedException(\InvalidArgumentException::class, 'The field "unknown" was not expected'); + $this->expectException(\InvalidArgumentException::class); $build = []; $display->setFieldOnBuild('unknown', ['#markup' => 'Unknown'], $build); }