From 9eae2471fa5a6f82f72edcb9d61925ee454d6a07 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Wed, 21 May 2014 20:53:28 -0700 Subject: [PATCH] Issue #2271939 by tim.plunkett: NodeType condition does not evaluate properly. --- .../node/lib/Drupal/node/Plugin/Condition/NodeType.php | 6 +++--- .../Drupal/node/Tests/Condition/NodeConditionTest.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/modules/node/lib/Drupal/node/Plugin/Condition/NodeType.php b/core/modules/node/lib/Drupal/node/Plugin/Condition/NodeType.php index f2c8e2453896..12e8bce3b043 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Condition/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Condition/NodeType.php @@ -61,7 +61,7 @@ public function validateConfigurationForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, array &$form_state) { - $this->configuration['bundles'] = $form_state['values']['bundles']; + $this->configuration['bundles'] = array_filter($form_state['values']['bundles']); parent::submitConfigurationForm($form, $form_state); } @@ -75,7 +75,7 @@ public function summary() { $bundles = implode(', ', $bundles); return t('The node bundle is @bundles or @last', array('@bundles' => $bundles, '@last' => $last)); } - $bundle = $this->configuration['bundles'][0]; + $bundle = reset($this->configuration['bundles']); return t('The node bundle is @bundle', array('@bundle' => $bundle)); } @@ -84,7 +84,7 @@ public function summary() { */ public function evaluate() { $node = $this->getContextValue('node'); - return in_array($node->getType(), $this->configuration['bundles']); + return !empty($this->configuration['bundles'][$node->getType()]); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php b/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php index 065cdcad116b..6ba87e622f6d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php @@ -55,20 +55,20 @@ function testConditions() { // Grab the node type condition and configure it to check against node type // of 'article' and set the context to the page type node. $condition = $manager->createInstance('node_type') - ->setConfig('bundles', array('article')) + ->setConfig('bundles', array('article' => 'article')) ->setContextValue('node', $page); $this->assertFalse($condition->execute(), 'Page type nodes fail node type checks for articles.'); // Check for the proper summary. $this->assertEqual('The node bundle is article', $condition->summary()); // Set the node type check to page. - $condition->setConfig('bundles', array('page')); + $condition->setConfig('bundles', array('page' => 'page')); $this->assertTrue($condition->execute(), 'Page type nodes pass node type checks for pages'); // Check for the proper summary. $this->assertEqual('The node bundle is page', $condition->summary()); // Set the node type check to page or article. - $condition->setConfig('bundles', array('page', 'article')); + $condition->setConfig('bundles', array('page' => 'page', 'article' => 'article')); $this->assertTrue($condition->execute(), 'Page type nodes pass node type checks for pages or articles'); // Check for the proper summary. $this->assertEqual('The node bundle is page or article', $condition->summary()); @@ -82,11 +82,11 @@ function testConditions() { $this->assertFalse($condition->execute(), 'Test type nodes pass node type checks for pages or articles'); // Check a greater than 2 bundles summary scenario. - $condition->setConfig('bundles', array('page', 'article', 'test')); + $condition->setConfig('bundles', array('page' => 'page', 'article' => 'article', 'test' => 'test')); $this->assertEqual('The node bundle is page, article or test', $condition->summary()); // Test Constructor injection. - $condition = $manager->createInstance('node_type', array('bundles' => array('article'), 'context' => array('node' => $article))); + $condition = $manager->createInstance('node_type', array('bundles' => array('article' => 'article'), 'context' => array('node' => $article))); $this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.'); } } -- GitLab