Skip to content
Snippets Groups Projects

Ignore configurability of fields (because not all fields have this property).

Merged Roderik Muit requested to merge issue/custom_elements-3467817:3467817-node-title-field into 3.x
1 unresolved thread

Closes #3467817

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
323 333 */
324 334 protected function getFieldDefinitions() {
335 // Override parent method: do not filter field definitions, all fields'
336 // display is configurable.
325 337 if (!isset($this->fieldDefinitions)) {
326 $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
327
328 $this->fieldDefinitions = $definitions;
329 foreach ($this->fieldDefinitions as $field_definition) {
330 if ($field_definition instanceof BaseFieldDefinition || $field_definition instanceof FieldDefinition) {
331 // We'd like to be able to configure all the fields thus override
332 // displayConfigurable to true for all field definitions.
333 $field_definition->setDisplayConfigurable($this->displayContext, TRUE);
334 }
335 }
338 $this->fieldDefinitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
  • Author Developer

    Cause of bug:

    During save, EntityDisplayBase::toArray() (the parent class) keeps the 'hidden' property set for any field that isn't "configurable". Non-fieldAPI fields like title are not set to be "configurable".

    Challenge:

    • EntityCeDisplay::getFieldDefinitions() changes most field definitions to be configurable.
    • The title field has no setDisplayConfigurable() method to do this: it is not a FieldConfig or BaseFieldDefinition object, but a FieldDefinitionOverride object.

    Also, IMHO it is not ideal to have to change those definitions.

    Fix: instead,

    • Override EntityCeDisplay::toArray() to not call parent EntityDisplayBase::toArray(), only grandparent ConfigEntityBase::toArray()
    • Simplify EntityCeDisplay::getFieldDefinitions() to not make anything configurable anymore. From now on, we will/must ignore a field definition's isDisplayConfigurable(). Note: current callers (there is only one) are not affected by this change.
  • Please register or sign in to reply
  • Roderik Muit added 1 commit

    added 1 commit

    Compare with previous version

  • Roderik Muit added 3 commits

    added 3 commits

    • 416c7c67 - 1 commit from branch project:3.x
    • a5d76eb6 - Ignore configurability of fields (because not all fields have this property).
    • 51c02c7f - Remove class definitions.

    Compare with previous version

  • merged

  • Please register or sign in to reply
    Loading