Issue #3144010 by danflanagan8, ravi.shankar, tim.plunkett, chrisolof, sorlov: New pseudo-fields cannot be removed, InvalidArgumentException thrown
parent
96dc01cf37
commit
9c7b7f7be2
core
misc/cspell
modules/layout_builder
src/EventSubscriber
tests
modules/layout_builder_extra_field_test
src/FunctionalJavascript
|
@ -572,6 +572,7 @@ fieldblock
|
|||
fieldbody
|
||||
fieldgroups
|
||||
fielditem
|
||||
fieldlayout
|
||||
fieldlinks
|
||||
fieldnames
|
||||
fieldsets
|
||||
|
|
|
@ -69,13 +69,16 @@ class PrepareLayout implements EventSubscriberInterface {
|
|||
if ($this->layoutTempstoreRepository->has($section_storage)) {
|
||||
$this->messenger->addWarning($this->t('You have unsaved changes.'));
|
||||
}
|
||||
// If the layout is an override that has not yet been overridden, copy the
|
||||
// sections from the corresponding default.
|
||||
elseif ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) {
|
||||
$sections = $section_storage->getDefaultSectionStorage()->getSections();
|
||||
foreach ($sections as $section) {
|
||||
$section_storage->appendSection($section);
|
||||
else {
|
||||
// If the layout is an override that has not yet been overridden, copy the
|
||||
// sections from the corresponding default.
|
||||
if ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) {
|
||||
$sections = $section_storage->getDefaultSectionStorage()->getSections();
|
||||
foreach ($sections as $section) {
|
||||
$section_storage->appendSection($section);
|
||||
}
|
||||
}
|
||||
// Add storage to tempstore regardless of what the storage is.
|
||||
$this->layoutTempstoreRepository->set($section_storage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
name: 'Layout Builder Extra Field test'
|
||||
type: module
|
||||
description: 'Support module for testing layout building.'
|
||||
package: Testing
|
||||
version: VERSION
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides hook implementations for Layout Builder tests.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_extra_field_info().
|
||||
*/
|
||||
function layout_builder_extra_field_test_entity_extra_field_info() {
|
||||
$extra['node']['bundle_with_section_field']['display']['layout_builder_extra_field_test'] = [
|
||||
'label' => t('New Extra Field'),
|
||||
'description' => t('New Extra Field description'),
|
||||
'weight' => 0,
|
||||
];
|
||||
return $extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_node_view().
|
||||
*/
|
||||
function layout_builder_extra_field_test_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
|
||||
if ($display->getComponent('layout_builder_extra_field_test')) {
|
||||
$build['layout_builder_extra_field_test'] = [
|
||||
'#markup' => 'A new extra field.',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -240,6 +240,30 @@ class LayoutBuilderUiTest extends WebDriverTestBase {
|
|||
$this->assertHighlightNotExists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests removing newly added extra field.
|
||||
*/
|
||||
public function testNewExtraField() {
|
||||
$assert_session = $this->assertSession();
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
// At this point layout builder has been enabled for the test content type.
|
||||
// Install a test module that creates a new extra field then clear cache.
|
||||
\Drupal::service('module_installer')->install(['layout_builder_extra_field_test']);
|
||||
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
|
||||
|
||||
// View the layout and try to remove the new extra field.
|
||||
$this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
|
||||
$assert_session->pageTextContains('New Extra Field');
|
||||
$this->clickContextualLink('.block-extra-field-blocknodebundle-with-section-fieldlayout-builder-extra-field-test', 'Remove block');
|
||||
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas'));
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$assert_session->pageTextContains('Are you sure you want to remove');
|
||||
$page->pressButton('Remove');
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$assert_session->pageTextNotContains('New Extra Field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms the presence of the 'is-layout-builder-highlighted' class.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue