Commit 7076c704 authored by catch's avatar catch

Issue #2632434 by yongt9412, EclipseGc, ivanjaros, Berdir: Conditions are not...

Issue #2632434 by yongt9412, EclipseGc, ivanjaros, Berdir: Conditions are not limited by available contexts
parent 8ee82f21
...@@ -237,7 +237,7 @@ protected function buildVisibilityInterface(array $form, FormStateInterface $for ...@@ -237,7 +237,7 @@ protected function buildVisibilityInterface(array $form, FormStateInterface $for
// @todo Allow list of conditions to be configured in // @todo Allow list of conditions to be configured in
// https://www.drupal.org/node/2284687. // https://www.drupal.org/node/2284687.
$visibility = $this->entity->getVisibility(); $visibility = $this->entity->getVisibility();
foreach ($this->manager->getDefinitions() as $condition_id => $definition) { foreach ($this->manager->getDefinitionsForContexts($form_state->getTemporaryValue('gathered_contexts')) as $condition_id => $definition) {
// Don't display the current theme condition. // Don't display the current theme condition.
if ($condition_id == 'current_theme') { if ($condition_id == 'current_theme') {
continue; continue;
......
...@@ -17,7 +17,7 @@ class BlockUiTest extends WebTestBase { ...@@ -17,7 +17,7 @@ class BlockUiTest extends WebTestBase {
* *
* @var array * @var array
*/ */
public static $modules = array('block', 'block_test', 'help'); public static $modules = array('block', 'block_test', 'help', 'condition_test');
protected $regions; protected $regions;
...@@ -248,6 +248,11 @@ public function testContextAwareBlocks() { ...@@ -248,6 +248,11 @@ public function testContextAwareBlocks() {
$this->drupalGet(''); $this->drupalGet('');
$this->assertText('No context mapping selected.'); $this->assertText('No context mapping selected.');
$this->assertNoText('User context found.'); $this->assertNoText('User context found.');
// Tests that conditions with missing context are not displayed.
$this->drupalGet('admin/structure/block/manage/testcontextawareblock');
$this->assertNoRaw('No existing type');
$this->assertNoFieldByXPath('//*[@name="visibility[condition_test_no_existing_type][negate]"]');
} }
/** /**
......
<?php
namespace Drupal\condition_test\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
/**
* Provides a condition that has a no existing context.
*
* @Condition(
* id = "condition_test_no_existing_type",
* label = @Translation("No existing type"),
* context = {
* "no_existing_type" = @ContextDefinition("no_existing_type", label = @Translation("No existing type")),
* }
* )
*/
class ConditionTestNoExistingType extends ConditionPluginBase {
/**
* {@inheritdoc}
*/
public function evaluate() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function summary() {
return $this->t('Condition that requires a non-existent context.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment