
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
- Create a Panopoly 3.0.x site using its composer template:
composer create-project panopoly/panopoly-composer-template:10.x-dev panopoly3 --no-interaction
- Install the default profile:
drush -y si panopoly
- Add the block_condition_published module via Composer and enable it.
- 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.
- Save the block config and the layout.
- Visit a published node provided by the Panopoly install.
- Note the block does not appear. This is the expected behavior.
- Edit the node. Uncheck the Published box and save.
- Note the block appears. This is the expected behavior.
- Visit the Add Content page for a content type, for example /node/add/panopoly_content_page.
- 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.
Issue fork block_condition_published-3488761
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 #3
cboyden commentedThe MR adds a simple check for a non-empty vid from the latest revision. If it's empty, the condition is treated the same as if the node object was empty.
Comment #4
grienauerThank you for the MR! we will check it out.
Comment #5
granik@cboyden thanks for your catch!
The problem can be, that if you skip the validation in your case, the module will not check if node is published or not. I guess there should be a check like
$node->isPublished()
, instead just returning TRUE.p.s. this check has been added just because of drupal moderation states(more info here), so in case if the regular published/unpublished status is used, there is no need to check the revision state. The code just checks all possible user cases.
I'll try to work on this issue as soon as possible.
Comment #7
granikCommitted to 1.0.x branch.