Skip to content
Snippets Groups Projects
Commit 9eae2471 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2271939 by tim.plunkett: NodeType condition does not evaluate properly.

parent 30def1f5
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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()]);
}
}
......@@ -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.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment