Skip to content
Snippets Groups Projects
Commit 6a0d7907 authored by Roderik Muit's avatar Roderik Muit
Browse files

Issue #3467817 by roderik, junkuncz: Node 'title' field cannot be enabled in CE UI

parent 416c7c67
Branches
Tags
1 merge request!76Ignore configurability of fields (because not all fields have this property).
Pipeline #254826 canceled
......@@ -2,10 +2,9 @@
namespace Drupal\custom_elements\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityDisplayBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Plugin\DefaultLazyPluginCollection as DefaultLazyPluginCollectionAlias;
use Drupal\custom_elements\CustomElementGenerator;
......@@ -212,7 +211,7 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
* {@inheritdoc}
*/
protected function init() {
// Do not call parent::init(); we don't need its display defaults.
// Override parent method: we don't need its display defaults.
if (!$this->targetEntityType) {
return;
}
......@@ -224,11 +223,11 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
$initialized = !empty($this->content) || $this->forceAutoProcessing;
if (!$initialized) {
// Enable components options as done in the regular entity_view_display.
// Enable components that are enabled in the regular entity_view_display.
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $entity_view_display */
$entity_view_display = \Drupal::service('entity_display.repository')
->getViewDisplay($this->targetEntityType, $this->bundle, $this->originalMode);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
$field_definitions = $this->getFieldDefinitions();
// @todo Add support for statically set values.
// Enable every component with "auto" that is enabled in the display.
......@@ -312,27 +311,29 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage) {
// Work around some of the parent code.
// Work around some of the parent method's code.
$this->hidden = [];
parent::preSave($storage);
unset($this->hidden);
}
/**
* Gets the definitions of the fields that are candidate for display.
* {@inheritdoc}
*/
public function toArray() {
// Skip over parent method: all fields' display is configurable, no field
// must be disallowed because of its definitions.
return ConfigEntityBase::toArray();
}
/**
* {@inheritdoc}
*/
protected function getFieldDefinitions() {
// Override parent method: do not filter field definitions, all fields'
// display is configurable.
if (!isset($this->fieldDefinitions)) {
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
$this->fieldDefinitions = $definitions;
foreach ($this->fieldDefinitions as $field_definition) {
if ($field_definition instanceof BaseFieldDefinition || $field_definition instanceof FieldDefinition) {
// We'd like to be able to configure all the fields thus override
// displayConfigurable to true for all field definitions.
$field_definition->setDisplayConfigurable($this->displayContext, TRUE);
}
}
$this->fieldDefinitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
}
return $this->fieldDefinitions;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment