Issue #2936360 by tim.plunkett, samuel.mortenson: Remove duplicate references to the "layout_builder__layout" field from Layout Builder
parent
bd583a846c
commit
a4c915aaff
|
@ -19,6 +19,7 @@ use Drupal\layout_builder\Plugin\Block\ExtraFieldBlock;
|
|||
use Drupal\layout_builder\InlineBlockEntityOperations;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
|
@ -62,8 +63,8 @@ function layout_builder_entity_type_alter(array &$entity_types) {
|
|||
function layout_builder_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) {
|
||||
// Hides the Layout Builder field. It is rendered directly in
|
||||
// \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
|
||||
unset($form['fields']['layout_builder__layout']);
|
||||
$key = array_search('layout_builder__layout', $form['#fields']);
|
||||
unset($form['fields'][OverridesSectionStorage::FIELD_NAME]);
|
||||
$key = array_search(OverridesSectionStorage::FIELD_NAME, $form['#fields']);
|
||||
if ($key !== FALSE) {
|
||||
unset($form['#fields'][$key]);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use Drupal\Core\Plugin\Context\EntityContext;
|
|||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
use Drupal\layout_builder\Section;
|
||||
use Drupal\layout_builder\SectionComponent;
|
||||
use Drupal\layout_builder\SectionStorage\SectionStorageTrait;
|
||||
|
@ -110,10 +111,10 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
|
|||
$bundle = $this->getTargetBundle();
|
||||
|
||||
if ($new_value) {
|
||||
$this->addSectionField($entity_type_id, $bundle, 'layout_builder__layout');
|
||||
$this->addSectionField($entity_type_id, $bundle, OverridesSectionStorage::FIELD_NAME);
|
||||
}
|
||||
else {
|
||||
$this->removeSectionField($entity_type_id, $bundle, 'layout_builder__layout');
|
||||
$this->removeSectionField($entity_type_id, $bundle, OverridesSectionStorage::FIELD_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,8 +275,8 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
|
|||
* The sections.
|
||||
*/
|
||||
protected function getRuntimeSections(FieldableEntityInterface $entity) {
|
||||
if ($this->isOverridable() && !$entity->get('layout_builder__layout')->isEmpty()) {
|
||||
return $entity->get('layout_builder__layout')->getSections();
|
||||
if ($this->isOverridable() && !$entity->get(OverridesSectionStorage::FIELD_NAME)->isEmpty()) {
|
||||
return $entity->get(OverridesSectionStorage::FIELD_NAME)->getSections();
|
||||
}
|
||||
|
||||
return $this->getSections();
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\field_ui\Form\EntityViewDisplayEditForm;
|
||||
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
use Drupal\layout_builder\SectionStorageInterface;
|
||||
|
||||
/**
|
||||
|
@ -48,8 +49,8 @@ class LayoutBuilderEntityViewDisplayForm extends EntityViewDisplayEditForm {
|
|||
$form = parent::form($form, $form_state);
|
||||
|
||||
// Remove the Layout Builder field from the list.
|
||||
$form['#fields'] = array_diff($form['#fields'], ['layout_builder__layout']);
|
||||
unset($form['fields']['layout_builder__layout']);
|
||||
$form['#fields'] = array_diff($form['#fields'], [OverridesSectionStorage::FIELD_NAME]);
|
||||
unset($form['fields'][OverridesSectionStorage::FIELD_NAME]);
|
||||
|
||||
$is_enabled = $this->entity->isLayoutBuilderEnabled();
|
||||
if ($is_enabled) {
|
||||
|
@ -133,7 +134,7 @@ class LayoutBuilderEntityViewDisplayForm extends EntityViewDisplayEditForm {
|
|||
|
||||
$entity_type = $this->entityTypeManager->getDefinition($display->getTargetEntityTypeId());
|
||||
$query = $this->entityTypeManager->getStorage($display->getTargetEntityTypeId())->getQuery()
|
||||
->exists('layout_builder__layout');
|
||||
->exists(OverridesSectionStorage::FIELD_NAME);
|
||||
if ($bundle_key = $entity_type->getKey('bundle')) {
|
||||
$query->condition($bundle_key, $display->getTargetBundle());
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Drupal\Component\Plugin\DerivativeInspectionInterface;
|
|||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
|
||||
/**
|
||||
* Methods to help with entities using the layout builder.
|
||||
|
@ -65,7 +66,7 @@ trait LayoutEntityHelperTrait {
|
|||
return $entity->getSections();
|
||||
}
|
||||
elseif ($this->isEntityUsingFieldOverride($entity)) {
|
||||
return $entity->get('layout_builder__layout')->getSections();
|
||||
return $entity->get(OverridesSectionStorage::FIELD_NAME)->getSections();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -102,7 +103,7 @@ trait LayoutEntityHelperTrait {
|
|||
* TRUE if the entity is using a field for a layout override.
|
||||
*/
|
||||
protected function isEntityUsingFieldOverride(EntityInterface $entity) {
|
||||
return $entity instanceof FieldableEntityInterface && $entity->hasField('layout_builder__layout');
|
||||
return $entity instanceof FieldableEntityInterface && $entity->hasField(OverridesSectionStorage::FIELD_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,13 @@ use Symfony\Component\Routing\RouteCollection;
|
|||
*/
|
||||
class OverridesSectionStorage extends SectionStorageBase implements ContainerFactoryPluginInterface, OverridesSectionStorageInterface, SectionStorageLocalTaskProviderInterface {
|
||||
|
||||
/**
|
||||
* The field name used by this storage.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FIELD_NAME = 'layout_builder__layout';
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
|
@ -127,8 +134,8 @@ class OverridesSectionStorage extends SectionStorageBase implements ContainerFac
|
|||
if (strpos($id, '.') !== FALSE) {
|
||||
list($entity_type_id, $entity_id) = explode('.', $id, 2);
|
||||
$entity = $this->entityTypeManager->getStorage($entity_type_id)->load($entity_id);
|
||||
if ($entity instanceof FieldableEntityInterface && $entity->hasField('layout_builder__layout')) {
|
||||
return $entity->get('layout_builder__layout');
|
||||
if ($entity instanceof FieldableEntityInterface && $entity->hasField(static::FIELD_NAME)) {
|
||||
return $entity->get(static::FIELD_NAME);
|
||||
}
|
||||
}
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" ID for the "%s" section storage type is invalid', $id, $this->getStorageType()));
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_builder\Functional;
|
|||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
use Drupal\layout_builder\Section;
|
||||
use Drupal\layout_builder\SectionComponent;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
@ -20,13 +21,6 @@ class LayoutSectionTest extends BrowserTestBase {
|
|||
*/
|
||||
public static $modules = ['field_ui', 'layout_builder', 'node', 'block_test'];
|
||||
|
||||
/**
|
||||
* The name of the layout section field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName = 'layout_builder__layout';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -226,7 +220,7 @@ class LayoutSectionTest extends BrowserTestBase {
|
|||
]);
|
||||
$entity->addTranslation('es', [
|
||||
'title' => 'Translated node title',
|
||||
$this->fieldName => [
|
||||
OverridesSectionStorage::FIELD_NAME => [
|
||||
[
|
||||
'section' => new Section('layout_twocol', [], [
|
||||
'foo' => new SectionComponent('foo', 'first', [
|
||||
|
@ -373,7 +367,7 @@ class LayoutSectionTest extends BrowserTestBase {
|
|||
'value' => 'The node body',
|
||||
],
|
||||
],
|
||||
$this->fieldName => $section_values,
|
||||
OverridesSectionStorage::FIELD_NAME => $section_values,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\layout_builder\Kernel;
|
||||
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
use Drupal\layout_builder\Section;
|
||||
|
||||
/**
|
||||
|
@ -56,7 +57,7 @@ class LayoutBuilderFieldLayoutCompatibilityTest extends LayoutBuilderCompatibili
|
|||
// Add a layout override.
|
||||
$this->enableOverrides();
|
||||
/** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
|
||||
$field_list = $this->entity->get('layout_builder__layout');
|
||||
$field_list = $this->entity->get(OverridesSectionStorage::FIELD_NAME);
|
||||
$field_list->appendSection(new Section('layout_onecol'));
|
||||
$this->entity->save();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_builder\Kernel;
|
|||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
use Drupal\layout_builder\Section;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +36,7 @@ class LayoutBuilderInstallTest extends LayoutBuilderCompatibilityTestBase {
|
|||
// Add a layout override.
|
||||
$this->enableOverrides();
|
||||
$this->entity = $this->reloadEntity($this->entity);
|
||||
$this->entity->get('layout_builder__layout')->appendSection(new Section('layout_onecol'));
|
||||
$this->entity->get(OverridesSectionStorage::FIELD_NAME)->appendSection(new Section('layout_onecol'));
|
||||
$this->entity->save();
|
||||
|
||||
// The rendered entity has now changed. The non-configurable field is shown
|
||||
|
@ -50,7 +51,7 @@ class LayoutBuilderInstallTest extends LayoutBuilderCompatibilityTestBase {
|
|||
$this->assertNotEmpty($this->cssSelect('.layout--onecol'));
|
||||
|
||||
// Removing the layout restores the original rendering of the entity.
|
||||
$this->entity->get('layout_builder__layout')->removeSection(0);
|
||||
$this->entity->get(OverridesSectionStorage::FIELD_NAME)->removeSection(0);
|
||||
$this->entity->save();
|
||||
$this->assertFieldAttributes($this->entity, $expected_fields);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_builder\Kernel;
|
|||
|
||||
use Drupal\entity_test\Entity\EntityTestBaseFieldDisplay;
|
||||
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
|
||||
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
||||
|
||||
/**
|
||||
* Tests the field type for Layout Sections.
|
||||
|
@ -42,10 +43,10 @@ class LayoutSectionItemListTest extends SectionStorageTestBase {
|
|||
}, $section_data);
|
||||
$entity = EntityTestBaseFieldDisplay::create([
|
||||
'name' => 'The test entity',
|
||||
'layout_builder__layout' => $section_data,
|
||||
OverridesSectionStorage::FIELD_NAME => $section_data,
|
||||
]);
|
||||
$entity->save();
|
||||
return $entity->get('layout_builder__layout');
|
||||
return $entity->get(OverridesSectionStorage::FIELD_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -112,13 +112,13 @@ class OverridesSectionStorageTest extends UnitTestCase {
|
|||
$entity_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
|
||||
$entity_without_layout = $this->prophesize(FieldableEntityInterface::class);
|
||||
$entity_without_layout->hasField('layout_builder__layout')->willReturn(FALSE);
|
||||
$entity_without_layout->get('layout_builder__layout')->shouldNotBeCalled();
|
||||
$entity_without_layout->hasField(OverridesSectionStorage::FIELD_NAME)->willReturn(FALSE);
|
||||
$entity_without_layout->get(OverridesSectionStorage::FIELD_NAME)->shouldNotBeCalled();
|
||||
$entity_storage->load('entity_without_layout')->willReturn($entity_without_layout->reveal());
|
||||
|
||||
$entity_with_layout = $this->prophesize(FieldableEntityInterface::class);
|
||||
$entity_with_layout->hasField('layout_builder__layout')->willReturn(TRUE);
|
||||
$entity_with_layout->get('layout_builder__layout')->willReturn('the_return_value');
|
||||
$entity_with_layout->hasField(OverridesSectionStorage::FIELD_NAME)->willReturn(TRUE);
|
||||
$entity_with_layout->get(OverridesSectionStorage::FIELD_NAME)->willReturn('the_return_value');
|
||||
$entity_storage->load('entity_with_layout')->willReturn($entity_with_layout->reveal());
|
||||
|
||||
$this->entityTypeManager->getStorage($expected_entity_type_id)->willReturn($entity_storage->reveal());
|
||||
|
|
Loading…
Reference in New Issue