Problem/Motivation
If one of the promoted nodes is deleted, the listing page returns the following PHP error:
Error: Call to a member function label() on null in Drupal\vais_promos\VaisPromoListBuilder->buildRow() (line 107 of modules/contrib/vais_promos/src/VaisPromoListBuilder.php).
This is because the code doesn't do a check that the node exists before calling label() on it and there's no hook_node_delete() to clean up promotions when the associated node is deleted.
$promoContent = $this->entityTypeManager->getStorage('node')->load($entity->promo_content->target_id);
$promoReferenceLink = Link::createFromRoute($promoContent->label(), 'entity.node.canonical', ['node' => $entity->promo_content->target_id]);
Steps to reproduce
Promote a node and then delete it.
Proposed resolution
Recommend adding a check that the node exists before calling label and also adding a hook_node_delete call to delete the promotion if the node it is associated with is deleted.
Issue fork vais_promos-3564136
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
jastraat commentedThe updated code successfully:
Comment #6
timozura commentedFix Added to 1.0.0-beta5 release.