Browse Source

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.
pull/819/head
Nigel Banks 5 years ago
parent
commit
5a0dbf7229
  1. 5
      src/Plugin/Condition/NodeHasTerm.php

5
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()
);
}

Loading…
Cancel
Save