Steps to reproduce

- install module and enter site id
- add path in pages tracking scope section, select 'Show for the listed pages' option and save form

Results

- No pages negate option is selected after form save.

Expected Results

- Form should show previously selected 'Show for the listed pages' option.

Comments

jasonawant’s picture

Priority: Normal » Minor

Hi,

I think I've tracked down this issue to how the radio form element is rendered. Also, this is the same UX for the block page visibility section. I've changed the priority to minor, as the default condition negate value is false, so the condition still evaluates correctly, However, it's rather poor UX.

In \Drupal\Core\Render\Element\Radio::preRenderRadio(), see

    if (isset($element['#return_value']) && $element['#value'] !== FALSE && $element['#value'] == $element['#return_value']) {
      $element['#attributes']['checked'] = 'checked';
    }

As the form option is false, this if statement is false and checked attribute is not set appropriately. Need to dig in to see if this is a core bug in radio rendering or in block visibility with how we manage this false option.

jasonawant’s picture

Here's a bit more info that I've tracked down related to the specific logic in the radio render.

- git history on 8.x branch does not reveal much about this logic.
- looks like this logic was added D7 theme_radio() when compared to D6 theme_radio(), see https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_rad...
- logic was added here > https://www.drupal.org/node/971120#comment-3706168

  • jasonawant committed c7ca89d on 8.x-1.x
    Issue #2447721 by jasonawant: Fixed render negate radio false option
    
jasonawant’s picture

Status: Active » Fixed

Alright, so I've posted a drupal core bug report here > https://www.drupal.org/node/2450637.

Until that's picked up, I've committed a fix that shuffles the negate #default_option from a boolean to an integer as a temp work-around

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.