diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 3ff21f66cfa27faa18499998be8309f660ce6b90..08d7508086cf59fcbaa970ff88dcc7c6325eb420 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -247,6 +247,7 @@ protected function buildVisibilityInterface(array $form, FormStateInterface $for if (isset($form['request_path'])) { $form['request_path']['#title'] = $this->t('Pages'); $form['request_path']['negate']['#type'] = 'radios'; + $form['request_path']['negate']['#default_value'] = (int) $form['request_path']['negate']['#default_value']; $form['request_path']['negate']['#title_display'] = 'invisible'; $form['request_path']['negate']['#options'] = [ $this->t('Show for the listed pages'), @@ -296,6 +297,13 @@ public function validate(array $form, FormStateInterface $form_state) { protected function validateVisibility(array $form, FormStateInterface $form_state) { // Validate visibility condition settings. foreach ($form_state->getValue('visibility') as $condition_id => $values) { + // All condition plugins use 'negate' as a Boolean in their schema. + // However, certain form elements may return it as 0/1. Cast here to + // ensure the data is in the expected type. + if (array_key_exists('negate', $values)) { + $values['negate'] = (bool) $values['negate']; + } + // Allow the condition to validate the form. $condition = $form_state->get(['conditions', $condition_id]); $condition_values = (new FormState()) diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php index e6709da0eb69653c6d66fa4d4c51852594272269..7053696b030528fb4682c80e20703ea25c8a7937 100644 --- a/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -40,9 +40,15 @@ function testBlockVisibility() { $edit['visibility[request_path][pages]'] = 'user*'; $edit['visibility[request_path][negate]'] = TRUE; $edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE; - $this->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block')); + $this->drupalGet('admin/structure/block/add/' . $block_name . '/' . $default_theme); + $this->assertFieldChecked('edit-visibility-request-path-negate-0'); + + $this->drupalPostForm(NULL, $edit, t('Save block')); $this->assertText('The block configuration has been saved.', 'Block was saved'); + $this->clickLink('Configure'); + $this->assertFieldChecked('edit-visibility-request-path-negate-1'); + $this->drupalGet(''); $this->assertText($title, 'Block was displayed on the front page.');