From a04a72c483e38b3e18c93a553d34228ca69f1d40 Mon Sep 17 00:00:00 2001 From: Simon Hieu Mai Date: Tue, 19 Apr 2022 11:54:54 -0500 Subject: [PATCH] The "Node has ancestor" condition shouldn't be required (#867) --- src/Plugin/Condition/NodeHasAncestor.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Condition/NodeHasAncestor.php b/src/Plugin/Condition/NodeHasAncestor.php index dd2abc54..ad6f1b99 100644 --- a/src/Plugin/Condition/NodeHasAncestor.php +++ b/src/Plugin/Condition/NodeHasAncestor.php @@ -96,7 +96,7 @@ class NodeHasAncestor extends ConditionPluginBase implements ContainerFactoryPlu '#type' => 'entity_autocomplete', '#title' => $this->t('Parent node(s)'), '#default_value' => $default_nids, - '#required' => TRUE, + '#required' => FALSE, '#description' => $this->t("Can be a collection node, compound object or paged content. Accepts multiple values separated by a comma."), '#target_type' => 'node', '#tags' => TRUE, @@ -130,9 +130,11 @@ class NodeHasAncestor extends ConditionPluginBase implements ContainerFactoryPlu public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // Entity autocomplete store things with target IDs, for convenience just // store the plain nid. - $this->configuration['ancestor_nids'] = array_map(function ($nid) { - return $nid['target_id']; - }, $form_state->getValue('ancestor_nids')); + if (!empty($form_state->getValue('ancestor_nids'))) { + $this->configuration['ancestor_nids'] = array_map(function ($nid) { + return $nid['target_id']; + }, $form_state->getValue('ancestor_nids')); + } $this->configuration['parent_reference_field'] = $form_state->getValue('parent_reference_field'); parent::submitConfigurationForm($form, $form_state); }