Skip to content
Snippets Groups Projects
Commit 7076c704 authored by catch's avatar catch
Browse files

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
No related branches found
No related tags found
No related merge requests found
......@@ -237,7 +237,7 @@ protected function buildVisibilityInterface(array $form, FormStateInterface $for
// @todo Allow list of conditions to be configured in
// https://www.drupal.org/node/2284687.
$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.
if ($condition_id == 'current_theme') {
continue;
......
......@@ -17,7 +17,7 @@ class BlockUiTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('block', 'block_test', 'help');
public static $modules = array('block', 'block_test', 'help', 'condition_test');
protected $regions;
......@@ -248,6 +248,11 @@ public function testContextAwareBlocks() {
$this->drupalGet('');
$this->assertText('No context mapping selected.');
$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.');
}
}
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