Verified Commit 386cfa84 authored by Dave Long's avatar Dave Long
Browse files

Issue #3385746 by acbramley, catch, longwave, danielveza, anybody, smustgrave,...

Issue #3385746 by acbramley, catch, longwave, danielveza, anybody, smustgrave, alexpott, larowlan, tim.plunkett: Automatically clear out the content key in view display when enabling Layout builder
parent b5008572
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -155,7 +155,14 @@ public function preSave(EntityStorageInterface $storage) {
        // Sort the components by weight.
        uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
        foreach ($components as $name => $component) {
          // We need to call setComponent so fields are added to the default
          // section if enabled. However, this also adds the fields to the
          // content key because of EntityDisplayBase::setComponent.
          // Therefore, we need to hide the fields afterward.
          // @todo simplify this in https://www.drupal.org/project/drupal/issues/3423225
          $this->setComponent($name, $component);
          $this->hidden[$name] = $name;
          unset($this->content[$name]);
        }
      }
      else {
+2 −0
Original line number Diff line number Diff line
@@ -48,10 +48,12 @@ protected function getExpectedDocument(): array {
    $document = parent::getExpectedDocument();
    array_unshift($document['data']['attributes']['dependencies']['module'], 'layout_builder');
    $document['data']['attributes']['hidden'][OverridesSectionStorage::FIELD_NAME] = TRUE;
    $document['data']['attributes']['hidden']['links'] = TRUE;
    $document['data']['attributes']['third_party_settings']['layout_builder'] = [
      'enabled' => TRUE,
      'allow_custom' => TRUE,
    ];
    $document['data']['attributes']['content'] = [];
    return $document;
  }

+5 −2
Original line number Diff line number Diff line
@@ -69,8 +69,11 @@ public function testNonDefaultViewMode(): void {
    $this->drupalGet("$field_ui_prefix/display/full");
    $assert_session->linkExists('Manage layout');
    $page->clickLink('Manage layout');
    // Confirm the body field only is shown once.
    $assert_session->elementsCount('css', '.field--name-body', 1);
    // The fields have all been hidden at this point.
    // Verify no Layout Builder blocks exist.
    $assert_session->addressEquals("$field_ui_prefix/display/full/layout");
    $assert_session->statusCodeEquals(200);
    $assert_session->elementsCount('css', '.layout-builder-block', 0);
  }

  /**
+2 −0
Original line number Diff line number Diff line
@@ -38,10 +38,12 @@ protected function getExpectedNormalizedEntity() {
    $expected = parent::getExpectedNormalizedEntity();
    array_unshift($expected['dependencies']['module'], 'layout_builder');
    $expected['hidden'][OverridesSectionStorage::FIELD_NAME] = TRUE;
    $expected['hidden']['links'] = TRUE;
    $expected['third_party_settings']['layout_builder'] = [
      'enabled' => TRUE,
      'allow_custom' => TRUE,
    ];
    $expected['content'] = [];
    return $expected;
  }

+4 −4
Original line number Diff line number Diff line
@@ -136,11 +136,11 @@ public function testDefaultValues(): void {
    $this->drupalGet($layout_builder_ui);
    $assert_session->pageTextContains('You are not authorized to access this page.');

    // The original body formatter is reflected in Field UI.
    $this->drupalGet($field_ui_prefix);
    $assert_session->fieldValueEquals('fields[body][type]', 'text_default');

    // Change the body formatter to Summary.
    // Change the body formatter to Summary and move the block back into
    // the content region.
    $assert_session->buttonExists('Show row weights')->click();
    $page->selectFieldOption('fields[body][region]', 'content');
    $page->selectFieldOption('fields[body][type]', 'text_summary_or_trimmed');
    $assert_session->assertWaitOnAjaxRequest();
    $page->pressButton('Save');
Loading