Commit 2eee2594 authored by alexpott's avatar alexpott
Browse files

Issue #2450637 by tim.plunkett, jasonawant: Block page visibility option "Show...

Issue #2450637 by tim.plunkett, jasonawant: Block page visibility option "Show for the listed pages" does not appear to save
parent 8b2f85b5
......@@ -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())
......
......@@ -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.');
......
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