Problem/Motivation

Therefore ContentEntityInterface::bundleFieldDefinitions() can currently be called with non-existant bundles (primarily for entity types that use configuration entities as bundles).

The Node entity, for example, does a $node_type = node_type_load($bundle); in its bundleFieldDefinitions() which fails in these cases. The only time $node_type is used currently is wrapped inside a if (isset($node_type->title_label)), which is why this doesn't fail currently.

Proposed resolution

Only load the field definitions when we actually need them instead of upfront in the constructor.

Remaining tasks

User interface changes

none.

API changes

none.

CommentFileSizeAuthor
#87 interdiff_86-87.txt1.2 KBpooja saraah
#87 2248795-87.patch5.11 KBpooja saraah
#86 2248795-86.patch5.1 KBShubham Chandra
#79 interdiff-76-79.txt1.25 KBsardara
#79 2248795-79.patch5.41 KBsardara
#76 interdiff-74-76.txt753 bytessardara
#76 2248795-76.patch5.11 KBsardara
#74 interdiff-72-74.txt744 bytessardara
#74 2248795-74.patch4.47 KBsardara
#73 interdiff-70-72.txt2.94 KBsardara
#72 interdiff-70-72.patch2.94 KBsardara
#72 2248795-72.patch3.58 KBsardara
#70 2248795-70.patch4.31 KBsandeep_jangra
#60 2248795-61.patch4.62 KBmohit_aghera
#60 2248795-60.patch4.62 KBmohit_aghera
#55 2248795-55.patch4.54 KBpflame
#53 2248795-53.patch3.41 KBpflame
#51 2248795-entity-display-delete-fail_51.patch25.31 KBswentel
#49 2248795-entity-display-delete-fail_49.patch25.28 KBBerdir
#44 interdiff.txt23.63 KByched
#44 2248795-entity-display-delete-fail_44.patch27.51 KByched
#43 interdiff.txt1.25 KByched
#43 2248795-entity-display-delete-fail_43.patch3.88 KByched
#39 2248795-entity-display-delete-fail_39.patch3.93 KByched
#33 2248795-2-entity-display-delete-fail_33-interdiff.txt975 bytesBerdir
#33 2248795-2-entity-display-delete-fail_33.patch6.23 KBBerdir
#31 2248795-2-entity-display-delete-fail_30.patch5.64 KBBerdir
#23 2248795-2-entity-display-delete-fail_23-interdiff.txt1.26 KBBerdir
#23 2248795-2-entity-display-delete-fail_23.patch6.34 KBBerdir
#15 2248795-2-entity-display-delete-fail_13.patch6.03 KBestoyausente
#10 2248795-2-entity-display-delete-fail_10.patch5.33 KBestoyausente
#2 2248795-2-entity-display-delete-fail.patch5.25 KBtstoeckler
#2 2248795-2-for-review.txt2.94 KBtstoeckler
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Can we maybe switch to only loading the field definitions when we actually need them instead of upfront in the constructor?

tstoeckler’s picture

Status: Active » Needs review
FileSize
2.94 KB
5.25 KB

Something like this maybe?

(The for-review patch is with -w)

tstoeckler’s picture

Berdir’s picture

Assigned: Unassigned » yched

Yeah, I think this makes sense, assigning to @yched to get feedback from him.

yched’s picture

Assigned: yched » Unassigned

A bit tedious to have to explicitely inititialize in so many entry points, but yeah, I vaguely suspected that at some point we'd have to untie that init() part from the object construction.

Only nit : feels slightly weird to see the various methods repeatedly and unconditionnally "initialize" the object, with the "initialize" method internally checking "nothing to do, actually, I've been initialized already".
--> Alternatively, we could leave init() untouched, and add $this->initialized || $this->init(); in those various places that need to make sure the Display is initialized ? Semantically, init() is done only once.

Status: Needs review » Needs work

The last submitted patch, 2: 2248795-2-entity-display-delete-fail.patch, failed testing.

Berdir’s picture

As bonus, this should allow us to remove the slow __wakeup(), see #2313053: Field storage and instance call toArray() in __wakeup() is very slow, remove it?.

Berdir’s picture

Issue tags: +Novice, +Needs reroll

Should be a Novice'ish task to re-roll this.

estoyausente’s picture

estoyausente’s picture

Status: Needs work » Needs review
Issue tags: +Amsterdam2014
yched’s picture

Status: Needs review » Reviewed & tested by the community

Alright, never mind #5, works for me.
RTBC if green.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2248795-2-entity-display-delete-fail_10.patch, failed testing.

tstoeckler’s picture

Assigned: Unassigned » tstoeckler

Will take a stab at this.

estoyausente’s picture

Status: Needs work » Needs review
FileSize
6.03 KB
estoyausente’s picture

+++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php
@@ -293,7 +293,7 @@ public function testRenameDeleteBundle() {
+      'module' => array('entity_test', 'text')

@tstoeckler I found the problem here and I resolve it but I'm not sure if this bundle needs "User" dependence or not. I think it isn't necessary... Any can review it? :-)

star-szr’s picture

Issue tags: -Needs reroll

Status: Needs review » Needs work

The last submitted patch, 15: 2248795-2-entity-display-delete-fail_13.patch, failed testing.

Status: Needs work » Needs review
Berdir’s picture

Status: Needs review » Needs work

Can you try to add a init() call to calculateDependencies() and check if that results in the previous dependencies?

estoyausente’s picture

@Berdir Yes, I will try it in my local enviroment ant test it, but I think that the testfail isn't for this patch because I execute the test in a clean environment and it had not fail it.

(I will try it anyway, thanks :) ).

estoyausente’s picture

I tried it but the test couldn't be execute (ajax error in the process). I don't know if I did something wrong or not. ^^

Berdir’s picture

My suggestion seems to be working.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Indeed, looks reasonable.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: 2248795-2-entity-display-delete-fail_23.patch, failed testing.

fgm’s picture

FWIW, when testing this patch (and variants of it) locally, I get around 5500 fails, not just 1.

Probably a needed followup once this is fixed: the test is actually trying to install all contrib modules, not just core: maybe this is not such a great idea, as some of them might have unexpected side effects (like switching the DB connection to MongoDB, with no way back).

fgm’s picture

Issue summary: View changes
yched’s picture

Assigned: tstoeckler » Unassigned
Issue tags: -Novice

Not novice anymore :-)

The last submitted patch, 23: 2248795-2-entity-display-delete-fail_23.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
5.64 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 31: 2248795-2-entity-display-delete-fail_30.patch, failed testing.

Berdir’s picture

Ok, this is not going to work without the sorting from #2350537: Enforce order of display of components in config export, the initializing apparently changes the order sometimes, so we need to make sure that it is consistent.

Berdir’s picture

Assigned: Unassigned » yched

Maybe we can summon @yched here as well :)

This might also help to convince him that sorting alphabetically is "the right thing to do"?

yched’s picture

Assigned: yched » Unassigned

Yeah, as I said in #2350537: Enforce order of display of components in config export, I'll stop fighting on alphabetical sort :-)

Just wondering how the 'initialized' property should play with __sleep() and __wakeup().
It's currently not part of the serialized keys in __sleep(), so an unserialized Display will come out with 'initialized' == FALSE.
Yet the role of init() is to massage $this->content and $this->hidden, and those do get serialized.
So a Display that was initialized, will come out of unserialization in the correct "already initialized" state ?
Meaning we should also include 'initialized' in the serialized keys, to avoid needlessly initializing it again ?

yched’s picture

re my own #35 : well, I guess that depends on what happened on the site between the moment the Display got serialized/persisted somewhere, and the moment it's read back/unserialized...

Maybe it's safer if unserialized displays have to replay init() to account for the current runtime context. At any rate, that's what current HEAD does (with init() called in __construct(), and __construct() called in __wakeup()). So yeah, never mind #35.

yched’s picture

Then, it's just unclear to me why we have to ksort in init() as well.
preSave() takes care of sorting before yamls are written.
init() is about preparing valid runtime values for $this->content / $this->hidden - why is order important in the runtime values ?

Berdir’s picture

I am not 100% sure, but it was definitely required.

I think it is related to the fact that we rebuild hidden, the test fails I had were because the order in hidden no longer matches.

yched’s picture

For those interested, this has been bugging me for a while, filed a patch for it : #2417817: Keep contrib modules out of ConfigImportAllTest

yched’s picture

So, removing the ksort in init() makes ConfigImportAllTest fail - #2417357: Testbot helper issue for [#2248795]

Using the debug snippet from #2230637-93: Create a Language field widget and the related formatter, looks like it's about the langcode field again. Investigating.

Side note : opened #2417839: Add code to ease debugging of ConfigImportAllTest fails to keep that debug snippet at hand :-)

yched’s picture

Related : if the patch changes the order of entries saved in core.entity_form_display.* / core.entity_view_display.*, we should also re-generate the ones shipped in core's default config ?

yched’s picture

It seems that doing the sorting in toArray() rather than preSave() makes it not needed in init().

I did not fully figure out why putting it in preSave() causes fails in ConfigImportAllTest, this was about 'langcode' appearing in different places, so this looks like a similar tricky race condition as we had in #2230637-103: Create a Language field widget and the related formatter. I don't really feel like repeating the same detective work that we had back then, and I think toArray() is the right place for this anyway :-)

yched’s picture

Updates of the core.entity_[form|view]_display.* shipped in default config with the new ordering.

Berdir’s picture

Works for me, although I'm not 100% convinced that toArray() is the right place. Your changes look fine to me, good call on updating the existing default configuration.

Who is going to RTBC this now? :)

lokapujya’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 44: 2248795-entity-display-delete-fail_44.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
25.28 KB

Reroll, the config file conflicts were a bit painful, I just deleted all the changes and then sorted it again.

Another issue added some sorting in the meantime, let's see if this works.

Status: Needs review » Needs work

The last submitted patch, 49: 2248795-entity-display-delete-fail_49.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
25.31 KB

rerolled - indeed painful patch for that :)

Status: Needs review » Needs work

The last submitted patch, 51: 2248795-entity-display-delete-fail_51.patch, failed testing.

pflame’s picture

Status: Needs work » Needs review
FileSize
3.41 KB

Here I provided a fresh patch with only changes to EntityDisplayBase.

I am not sure if we still need to re-order default config files. I ran only Entity Related Test Cases, all of them passed.

Status: Needs review » Needs work

The last submitted patch, 53: 2248795-53.patch, failed testing.

pflame’s picture

Status: Needs work » Needs review
FileSize
4.54 KB

Fixed the failed test case by adding below link before fetching the components

 $display = entity_load('entity_view_display', $display->id());

All previous tests, for example, testEntityDisplayCRUD loaded the entity using entity_load before checking it's component values. I hope, this is the correct way to test, please correct me if there is another way to make the test case pass.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

Status: Needs review » Needs work

The last submitted patch, 55: 2248795-55.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
4.62 KB
4.62 KB

Resolving conflicts and re-rolling for 8.4.x and 8.3.x respectively.

The last submitted patch, 60: 2248795-60.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 60: 2248795-61.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

andypost’s picture

Issue tags: +Needs reroll
sandeep_jangra’s picture

Assigned: Unassigned » sandeep_jangra
sandeep_jangra’s picture

Assigned: sandeep_jangra » Unassigned
Status: Needs work » Needs review
FileSize
4.31 KB

Added a reroll of patch #60

sardara’s picture

Status: Needs review » Needs work

The patch needs a general overhaul, much has changed in the init() method. The content and hidden variables are not accessed directly anymore, the(set|remove)Component methods are called now, so the current approach causes an infinite loop.

sardara’s picture

Status: Needs work » Needs review
FileSize
3.58 KB
2.94 KB

Re-rolled with some changes.
Moved the setting of the initialized variable to the beginning of the init method to avoid infinite recursion. The drawback is that the entity is already marked as initialized even if the procedure is not over yet. But using two variables seems overkill at the moment.

sardara’s picture

FileSize
2.94 KB

Whopsie wrong file extension for interdiff.

sardara’s picture

Assigned: Unassigned » sardara
FileSize
4.47 KB
744 bytes

There is still recursion happening. \Drupal\field_layout\Entity\FieldLayoutEntityDisplayTrait::init() extends the original init method, calling another method that ends up calling \Drupal\Core\Entity\EntityDisplayBase::getComponents() which calls the overridden init and so on.
Uploading a patch for fixing the this part, let's see what else is left out.
It's not very clean the new addition, but giving it a go for now.

Status: Needs review » Needs work

The last submitted patch, 74: 2248795-74.patch, failed testing. View results

sardara’s picture

Status: Needs work » Needs review
FileSize
5.11 KB
753 bytes

Two methods, ::toArray() and ::onDependencyRemoval(), were missing a call to the init method.

sardara’s picture

+++ b/core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php
@@ -103,7 +103,16 @@ protected function doGetLayout($layout_id, array $layout_settings) {
+    // The ::ensureLayout() method will methods that require initialization.

Missing verb "invoke".

Status: Needs review » Needs work

The last submitted patch, 76: 2248795-76.patch, failed testing. View results

sardara’s picture

The remaining test failures are caused by the FieldLayoutEntityFormDisplay/FieldLayoutEntityViewDisplay classes which need a layout id to be set. The ensureLayout() method is called during init, so normally during object construction. With this patch approach is not, so we either move the invocation of that method into the __construct or call ensureLayout in some/most of the methods of FieldLayoutEntityDisplayTrait.
The problem is that we have to make sure that also getLayoutId() has run the ensureLayout() first.
I'm giving it a go by moving the call to ensureLayout() back in the constructor. Since ensureLayout() calls setLayoutId() which indirectly calls the init() method and ends up needing the layout id to be set, we have to wrap the ensureLayout() so that the init is not called. This replicates the current state of the code, where the ensureLayout() is called before init.

sardara’s picture

Status: Needs work » Needs review
sardara’s picture

Assigned: sardara » Unassigned
sardara’s picture

I think it still needs test to cover for the bug described.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Shubham Chandra’s picture

Version: 9.4.x-dev » 9.5.x-dev
Issue tags: -Needs reroll
FileSize
5.1 KB

Rerolled patch #79 with Drupal 9.4.x

pooja saraah’s picture

Fixed failed commands on #86

Status: Needs review » Needs work

The last submitted patch, 87: 2248795-87.patch, failed testing. View results

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.