Skip to content

Call postLoad() hook by bundle #8 - #9

Open
simonbaese wants to merge 1 commit into
amcgowanca:8.x-1.xfrom
simonbaese:postload_by_bundle
Open

simonbaese wants to merge 1 commit into
amcgowanca:8.x-1.xfrom
simonbaese:postload_by_bundle

Conversation

@simonbaese

Copy link
Copy Markdown

Looking to resolve #8 with this pull request. I modified the suggested code because the given entities might have different bundles. Thus we have to get the entity classes for each entity and call the respective hook defined by the class.

Maybe we should add another check if the bundle is set for the entity in line 130. But I dont know if there is a scenario were the postLoad() hook is called for bundled and "not"-bundled entities at the same time.

@simonbaese

Copy link
Copy Markdown
Author

@amcgowanca Glad if you could review this pull request.

if (isset($this->bundleKey)) {
$entities_by_bundle = [];
foreach ($entities as $entity) {
$entities_by_bundle[$entity->get($this->bundleKey)->getString()][] = $entity;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonbaese Could we not use something like just $entity->bundle()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amcgowanca I was not really sure because you were checking for the bundleKey throughout the code. The method bundle() specifically looks for the value by the key 'bundle' in the entity (see ContentEntityBase) and as it is public it could also be overwritten.

@douggreen

douggreen commented Jan 6, 2020

Copy link
Copy Markdown
Contributor

I need something like this too. The patch I created before seeing this is at #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

postLoad() hook not called correctly in SqlContentEntityStorageTrait

3 participants