From 5a0dbf72299a58a041753c845d5a8bc0960be2e0 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 5 Jan 2021 12:35:43 +0000 Subject: [PATCH] Ran into issues with `node_has_term` condition from the Islandora module. It always saves to the block and fails to evaluate to false. It should not save if no value has been specified for term URI. Found the following in `web/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php`. ```php // In order to determine if a plugin is configured, we must compare it to // its default configuration. The default configuration of a plugin does // not contain context_mapping and it is not used when the plugin is not // configured, so remove the context_mapping from the instance config to // compare the remaining values. unset($instance_config['context_mapping']); if ($default_config === $instance_config) { unset($configuration[$instance_id]); } ``` When doing the comparison we have. ```php $default_config = [ "id" => "node_has_term", "logic" => "and", "negate" => false ]; $instance_config = [ "id" => "node_has_term", "logic" => "and", "negate" => false, "uri" => NULL, ]; ``` So the comparison fails and the configuration is stored and evaluated later causing issues since it fails to pass evaluation. Hence we need to change the default config to match the submitted values. --- src/Plugin/Condition/NodeHasTerm.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Condition/NodeHasTerm.php b/src/Plugin/Condition/NodeHasTerm.php index 8558e14b..c5ab2b76 100644 --- a/src/Plugin/Condition/NodeHasTerm.php +++ b/src/Plugin/Condition/NodeHasTerm.php @@ -84,7 +84,10 @@ class NodeHasTerm extends ConditionPluginBase implements ContainerFactoryPluginI */ public function defaultConfiguration() { return array_merge( - ['logic' => 'and'], + [ + 'logic' => 'and', + 'uri' => NULL, + ], parent::defaultConfiguration() ); }