Node object without revision causes fatal error

Created on 20 November 2024, 1 day ago

Problem/Motivation

The block visibility condition assumes there will be an existing revision if the node object is not empty when the condition is checked. This is not guaranteed to be true. If the node object is not empty and there's no revision, it causes a fatal error. This is happening on Panopoly and a child distribution; there may be other cases where the node object is not empty but there is not an existing revision.

Steps to reproduce

  1. Create a Panopoly 3.0.x site using its composer template: composer create-project panopoly/panopoly-composer-template:10.x-dev panopoly3 --no-interaction
  2. Install the default profile: drush -y si panopoly
  3. Add the block_condition_published module via Composer and enable it.
  4. In the Block Layout admin page, add a block to a region and configure it to display only if the node is unpublished. For example, add the Who's Online block to the Highlighted region and check the boxes for Published and Negate the condition.
  5. Save the block config and the layout.
  6. Visit a published node provided by the Panopoly install.
  7. Note the block does not appear. This is the expected behavior.
  8. Edit the node. Uncheck the Published box and save.
  9. Note the block appears. This is the expected behavior.
  10. Visit the Add Content page for a content type, for example /node/add/panopoly_content_page.
  11. Note the error: "Call to a member function get() on null in Drupal\block_condition_published\Plugin\Condition\NodePublishedState->evaluate() (line 136 of modules/contrib/block_condition_published/src/Plugin/Condition/NodePublishedState.php)."

Proposed resolution

Check to make sure the revision ID exists before trying to get the published status.

Remaining tasks

MR and test.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cboyden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024