Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call postLoad() hook by bundle #8 #9

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from

Conversation

simonbaese
Copy link

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
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
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
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
Copy link
Contributor

douggreen commented Jan 6, 2020

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