diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 269a98b392243192b176da33a315574185a45dc6..42dfbc3b2f6e2f6805da08232366e46c7a693204 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -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; diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php index f2bcaae2dbff3154aac04427300a62be3a73e146..65183cdce629f43e1b49343bd4840939513ece6f 100644 --- a/core/modules/block/src/Tests/BlockUiTest.php +++ b/core/modules/block/src/Tests/BlockUiTest.php @@ -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]"]'); } /** diff --git a/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/ConditionTestNoExistingType.php b/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/ConditionTestNoExistingType.php new file mode 100644 index 0000000000000000000000000000000000000000..ef00053fe3b56dd51d5f61ea0f444d7b88880df8 --- /dev/null +++ b/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/ConditionTestNoExistingType.php @@ -0,0 +1,34 @@ +<?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.'); + } + +}