Problem/Motivation

During __construct(), EntityDisplayBase ensures that all extra fields are correctly added as components.
However, it does so by directly manipulating internal variables, bypassing ::setComponent().

Any subclasses, such as the one added in #2922033: Use the Layout Builder for EntityViewDisplays, needs to be able to track the components as they are added.
Using the API will allow this.

See #2925657: EntityDisplayBase::init() should use ::setComponent() for fields and #2953656: No ability to control "extra fields" with Layout Builder

Proposed resolution

Use ::setComponent() correctly

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

See core/profiles/standard/config/install/core.entity_view_display.node.article.default.yml line 55-59 for an example of a correctly configured extra field.
Hence the needed changes to the test coverage. They were asserting that incomplete config was returned!

tedbow’s picture

Status: Needs review » Reviewed & tested by the community

The changes look good.
Looking at \Drupal\Core\Entity\EntityDisplayBase now the only instance of $this->content[$name] = is inside \Drupal\Core\Entity\EntityDisplayBase::setComponent()

And the only instance of $this->hidden[$name] = TRUE; is in \Drupal\Core\Entity\EntityDisplayBase::removeComponent()

RTBC, if patches test/fail as expected I think it is good.

The last submitted patch, 2: 2956202-extrafield-2-FAIL.patch, failed testing. View results

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs upgrade path, +Needs upgrade path tests

Discussed with @tim.plunkett. He mentioned that this will result in changes to config exports as there are new entries added to entity displays for each field. So we need an upgrade path here to re-save the config so it happens on update rather than randomly adding diffs when something else is updated.

Per @tim.plunkett this is a blocker for #2953656: No ability to control "extra fields" with Layout Builder and the workaround without this fix is icky and possibly a performance issue. Layout Builder is beta experimental and so can have new BC functionality added in patch releases etc., so not having the issue affects how cleanly the fix can be backported to beta. However, since this is an issue with the entity system itself and upgrade paths that update config are preferably minor-only: I think we should start by getting this into 8.6.x, and then after commit we can decide whether it's better to backport this or not.

Thanks!

tim.plunkett’s picture

Waited for ConfigEntityUpdater to go in, now this is much more straightforward.

Status: Needs review » Needs work

The last submitted patch, 6: 2956202-extrafield-6-PASS.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
5.99 KB
3.74 KB
+++ b/core/modules/system/tests/src/Functional/Update/UpdateEntityDisplayTest.php
@@ -18,14 +18,16 @@ class UpdateEntityDisplayTest extends UpdatePathTestBase {
-      __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
+      __DIR__ . '/../../../../tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',

Hmm, I can't make this change. Whoops.

(The other update was written for 8.3.0, so testing it on 8.4.0 doesn't work)

Splitting out the new test method to a new class. Interdiff looks destructive but it's okay :)

amateescu’s picture

I was discussing this issue with Tim and I tried to use the existing test fixture locally and I can't seem to replicate the failures from #6. Let's try this out quickly, the interdiff is relative to the PASS patch from #6.

tedbow’s picture

Status: Needs review » Reviewed & tested by the community

Looks great! Good tests!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: 2956202-9.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
6.29 KB

Thanks @amateescu for steering me back to sanity there :)

Failed due to another post_update hook being added to system.
No interdiff.

tim.plunkett’s picture

Priority: Normal » Major
Issue tags: +blocker

This hard blocks #2953656: No ability to control "extra fields" with Layout Builder which is itself a major bug (albeit one in an experimental module)

tedbow’s picture

duh!! Sorry about setting to RTBC in #10 when it actually needed a reroll. By the end of my review I had forgotten that had to reroll the patch for system.post_update.php

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Sorry to drop this back to NW, but the comment needs work

  1. +++ b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
    @@ -166,7 +166,7 @@ public function testExtraFieldComponent() {
    -    $this->assertEqual($display->getComponent('display_extra_field'), ['weight' => 5, 'region' => 'content']);
    +    $this->assertEqual($display->getComponent('display_extra_field'), ['weight' => 5, 'region' => 'content', 'settings' => [], 'third_party_settings' => []]);
    

    could we split this array over multiple lines for readability? think it would fail phpcs as is

  2. +++ b/core/modules/system/system.post_update.php
    @@ -139,3 +141,32 @@ function system_post_update_change_delete_action_plugins() {
    +    // If any extra fields have are used as a component, resave the display with
    +    // the updated component information.
    

    the english is off here

tedbow’s picture

Status: Needs work » Needs review
FileSize
1.91 KB
6.35 KB

Fixes for #15

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @tedbow!

larowlan’s picture

Crediting @xjm for the review that asked for an update path.

Not crediting my nit-review

larowlan’s picture

Version: 8.6.x-dev » 8.5.x-dev

Committed as 223216c and pushed to 8.6.x.

Leaving at RTBC and will discuss with @xjm re back-port question raised in #5

  • larowlan committed 223216c on 8.6.x
    Issue #2956202 by tim.plunkett, tedbow, amateescu, xjm:...

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2956202-16.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Status: Needs work » Fixed

A little late for a backport to 8.5, I think we can be happy this got into 8.6 :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.