- Issue created by @IT-Cru
- Merge request !70Issue #3485273 by it-cru: Call to a member function getTypedData() on null → (Open) created by IT-Cru
- 🇩🇪Germany IT-Cru Munich
My little change in IF-statement on opened MR fixed this issue.
Strange thing is, that in both variants entity gets loaded properly, but only with my change in IF-statement
$entity-getTypedData()
doesn't throw any error. - 🇨🇦Canada mparker17 UTC-4
@it-cru, awesome, thank you very much!
This patch looks great!
But, I think this is a common-enough scenario that we should have a test to make sure that this issue doesn't regress (that's why I'm marking it as "Needs work" and adding the "Needs tests" tag).
@it-cru, do you feel comfortable writing a test? (I am happy to help if you'd like!) If not, then I would be happy to write the test.
I think the reason why your change makes the error go away is because there are some cases where
$this->entityTypeManager->getStorage($entity_type_id)->load($id)
returns NULL (e.g.: I could see this happening if an entity was deleted from Drupal, but the corresponding entry in the ElasticSearch index hadn't been deleted yet).Because PHP interprets NULL as "false-y", the subsequent code (i.e.:
$datasource->getItemId($entity->getTypedData())
) isn't run (and doesn't throw an error) after your change.