diff --git a/core/modules/field_layout/field_layout.info.yml b/core/modules/field_layout/field_layout.info.yml index 16e67f0..62f225a 100644 --- a/core/modules/field_layout/field_layout.info.yml +++ b/core/modules/field_layout/field_layout.info.yml @@ -4,5 +4,3 @@ description: 'Adds layout capabilities to the Field UI.' package: Core (Experimental) version: VERSION core: 8.x -dependencies: - - field_ui diff --git a/core/modules/field_layout/field_layout.module b/core/modules/field_layout/field_layout.module index 84e6423..01e6bb8 100644 --- a/core/modules/field_layout/field_layout.module +++ b/core/modules/field_layout/field_layout.module @@ -11,7 +11,6 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Url; use Drupal\field_layout\Form\FieldLayoutEntityFormDisplayEditForm; use Drupal\field_layout\Form\FieldLayoutEntityViewDisplayEditForm; @@ -23,7 +22,7 @@ function field_layout_help($route_name, RouteMatchInterface $route_match) { case 'help.page.field_layout': $output = '

' . t('About') . '

'; $output .= '

' . t('The Field Layout module allows you to arrange fields into regions for content forms and displays.') . '

'; - $output .= '

' . t('For more information, see the help page for Field UI or the online documentation for the Field Layout module.', [':field-ui-help' => Url::fromRoute('help.page', ['name' => 'field_ui'])->toString(), ':field-layout-documentation' => 'https://www.drupal.org/documentation/modules/@todo_once_module_name_is_decided_upon']) . '

'; + $output .= '

' . t('For more information, see the online documentation for the Field Layout module.', [':field-layout-documentation' => 'https://www.drupal.org/documentation/modules/@todo_once_module_name_is_decided_upon']) . '

'; return $output; } } @@ -33,8 +32,10 @@ function field_layout_help($route_name, RouteMatchInterface $route_match) { */ function field_layout_entity_type_alter(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_types['entity_view_display']->setFormClass('edit', FieldLayoutEntityViewDisplayEditForm::class); - $entity_types['entity_form_display']->setFormClass('edit', FieldLayoutEntityFormDisplayEditForm::class); + if (\Drupal::moduleHandler()->moduleExists('field_ui')) { + $entity_types['entity_view_display']->setFormClass('edit', FieldLayoutEntityViewDisplayEditForm::class); + $entity_types['entity_form_display']->setFormClass('edit', FieldLayoutEntityFormDisplayEditForm::class); + } } /** diff --git a/core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php b/core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php index 3e8a8e8..b769bee 100644 --- a/core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php +++ b/core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php @@ -107,20 +107,15 @@ public static function updateFieldLayout($entity_type_id, EntityInterface $entit if ($form_state->isSubmitted() && $entity instanceof ThirdPartySettingsInterface) { $old_layout = $entity->getThirdPartySetting('field_layout', 'layout'); $new_layout = $form_state->getValue('field_layout'); - if ($old_layout === $new_layout) { - $fields = []; - foreach ($form_state->getValue('fields') as $field_name => $values) { - $fields[$field_name]['region'] = $values['region']; - } - } - else { - $entity->setThirdPartySetting('field_layout', 'layout', $new_layout); + $fields = []; + foreach ($form_state->getValue('fields') as $field_name => $values) { // If the layout is changing, reset all fields. // @todo Devise a mechanism for mapping old regions to new ones in // https://www.drupal.org/node/2796877. - $fields = []; + $fields[$field_name]['region'] = $old_layout === $new_layout ? $values['region'] : 'hidden'; } $entity->setThirdPartySetting('field_layout', 'fields', $fields); + $entity->setThirdPartySetting('field_layout', 'layout', $new_layout); } } diff --git a/core/modules/field_layout/tests/src/FunctionalJavascript/EntityViewLayoutTest.php b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php similarity index 66% rename from core/modules/field_layout/tests/src/FunctionalJavascript/EntityViewLayoutTest.php rename to core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php index 2f46a0b..3c81d7c 100644 --- a/core/modules/field_layout/tests/src/FunctionalJavascript/EntityViewLayoutTest.php +++ b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php @@ -5,16 +5,16 @@ use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** - * Tests using field layout for entity view displays. + * Tests using field layout for entity displays. * * @group field_layout */ -class EntityViewLayoutTest extends JavascriptTestBase { +class FieldLayoutTest extends JavascriptTestBase { /** * {@inheritdoc} */ - public static $modules = ['field_layout', 'node']; + public static $modules = ['field_layout', 'field_ui', 'node']; /** * {@inheritdoc} @@ -25,6 +25,13 @@ protected function setUp() { $this->createContentType([ 'type' => 'article', ]); + $this->createNode([ + 'type' => 'article', + 'title' => 'The node title', + 'body' => [[ + 'value' => 'The node body', + ]], + ]); $this->drupalLogin($this->drupalCreateUser([ 'access administration pages', 'administer content types', @@ -37,12 +44,15 @@ protected function setUp() { } /** - * Tests the use of field layout on the admin side. + * Tests the use of field layout for entity view displays. */ - public function testAdmin() { - $this->drupalGet('admin/structure/types/manage/article/display'); + public function testEntityView() { + $this->drupalGet('node/1'); + $this->assertSession()->elementExists('css', '.field--name-body'); + $this->assertSession()->elementNotExists('css', '.field-layout-region-left'); // The default layout is in use. + $this->drupalGet('admin/structure/types/manage/article/display'); $this->assertEquals(['Content', 'Disabled'], $this->getRegionTitles()); // Switch the layout to two columns. @@ -53,6 +63,10 @@ public function testAdmin() { $this->assertSession()->pageTextContains('Your settings have been saved.'); $this->assertEquals(['Left', 'Right', 'Disabled'], $this->getRegionTitles()); + $this->drupalGet('node/1'); + $this->assertSession()->elementNotExists('css', '.field-layout-region-left'); + $this->assertSession()->elementNotExists('css', '.field--name-body'); + // After a refresh the new regions are still there. $this->drupalGet('admin/structure/types/manage/article/display'); $this->assertEquals(['Left', 'Right', 'Disabled'], $this->getRegionTitles()); @@ -67,6 +81,15 @@ public function testAdmin() { $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); + + $this->drupalGet('admin/structure/types/manage/article/display'); + $page->pressButton('Show row weights'); + $this->getSession()->getPage()->selectFieldOption('fields[links][region]', 'right'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->submitForm([], 'Save'); + + $this->drupalGet('node/1'); + $this->assertSession()->elementExists('css', '.field-layout-region-left .field--name-body'); } /**