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 f2c8e2453896b1fe39e89be2562ec52a44c9ea54..12e8bce3b0433fdb575f37f613fc94ab15124d5c 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 065cdcad116b559c54e297e6f91878612e098e2b..6ba87e622f6defc132a66d5de2c239bef3a2fe4b 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.'); } }