Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When migrating node translations the following error occurs:
Fatal error: Call to a member function getThirdPartySetting() on null in modules/contrib/scheduler/scheduler.module on line 333
I'm on Drupal 8.4;
The following code expects a valid entity:
// If the node type is not enabled for Scheduler then do nothing.
if (!$entity->getThirdPartySetting('scheduler', 'publish_enable', $config->get('default_publish_enable'))) {
return;
};
A similar issue can be found here: #2868294: Call to a member function getThirdPartySetting() on null in ContentTranslationManager
Comment | File | Size | Author |
---|---|---|---|
#9 | 2902512-9.getThirdPartySetting_on_null.patch | 2.12 KB | jonathan1055 |
|
Comments
Comment #2
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #3
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThat's interesting. Thanks for the patch and link to the other issue.
It would seem that your patch should fix the problem, and obviously won't cause any current tests to fail. But I'd like to try and replicate it before I fix it (always a good idea). Do you know how the reproduction steps could be made simple? Where you migrating from a 7.x to 8.x site?
Jonathan
Comment #4
mpp CreditAttribution: mpp commentedIndeed, I was migrating a node translation from Drupal 7.
Comment #5
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHaving thought about this a bit more, is it actually the contrib module's responsibility to ensure that
$node->type->entity
returns a valid entity object? There may be many 3rd-party implementations ofhook_ENTITY_TYPE_presave()
for node entities and I would expect it to be the initiating function's duty to ensure the $node object is complete? If we fix this in Scheduler, is it just hiding the problem, and will it have to be fixed in every other hook_node_presave() that might be invoked during node translation migration? Just asking the question ...Comment #6
mpp CreditAttribution: mpp commentedAccording to its signature the method expects an EntityInterface:
So normally you can only perform operations on that interface, in this case I'd assume the operation getEntityType() would suffice.
Now it appears that core has a number of instances where it doesn't respect the interface and just grabs publicly available properties:
Since the ENTITY_TYPE in your case is node (scheduler_node_presave) you 'could' presume the $node parameter is a NodeTypeInterface but still, accessing properties directly seems fishy.
Comment #7
taggartj CreditAttribution: taggartj as a volunteer commentedHad the same issue
Error: Call to a member function getThirdPartySetting() on null in /app/web/modules/contrib/scheduler/scheduler.module on line 333 #0 [internal function]: scheduler_node_presave(Object(Drupal\node\Entity\Node))
After testing this patch in PHP 7.1
https://www.drupal.org/files/issues/scheduler_fatal_error_call_to_member...
aka composer
patches":
"drupal/scheduler": {
"site install fix": "https://www.drupal.org/files/issues/scheduler_fatal_error_call_to_member..."
}
allowed me to get back in business !
thanks @ mpp
as you saved me time to make my own lol.
also Thanks for the hooks it made workbench integration not so bad.
Comment #8
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi taggartj,
What kind of things were you doing when the error happened? I'd like to replicate this.
@mmp,
Yes I see that it might be better if we use the functions in the EntityInterface I will try this.
Comment #9
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI tried to use methods available in $node to detect if this parameter is as expected, for example
$node->getEntityTypeId()
,$node->getType()
and$node->getEntityType()
to determine if methodgetThirdPartySetting()
exists. I could not get it working as desired so decided to be safe and simply check for NULL as before.Comment #11
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI'm going to call this fixed for now. However, it would be useful to add a test to cover the problem.