Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Issue priority Notmal
Prioritized changes The main goal of this issue is usability

Steps to reproduce:
1. Set user status to blocked
2. Go to user edit form
3. Notice that the user status radio buttons are not showing any status

I believe this is because the value for 'blocked' is 0.

I can see this issue in latest 8.x version. See the screen below.

user-edit-status-unchecked

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zakir.gori’s picture

Version: 8.0.0-beta11 » 8.0.x-dev
Issue summary: View changes
FileSize
63.88 KB
willzyx’s picture

Status: Active » Needs review
FileSize
588 bytes

user status, used as #default_value in the radio element, is checked using \Drupal\user\UserInterface::isActive() which return a boolean.
Comment in \Drupal\Core\Render\Element\Radios::processRadios() say:

// Use default or FALSE. A value of FALSE means that the radio button is
// not 'checked'.
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : FALSE,

this is a little weird..if user account is blocked (status == FALSE) the default value is not considered

masipila’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and succesfully tested.

@willzyx, regarding your wondering. I believe that the documentation is correct.

  • \Drupal\user\UserInterface::isActive() returns a boolean FALSE for blocked users
  • As you mentioned, boolean FALSE means that radio button is not-checked. This is exactly what this bug was about.
  • We are storing the user status as 0 or 1. With your patch we the blocked status will be 0 on the radio button and it works as expected.

Thanks for a quick patch!

Cheers,
Markus

willzyx’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Need tests

I think we need some tests..

willzyx’s picture

Status: Needs work » Needs review
Issue tags: -Need tests
FileSize
1.43 KB
2.19 KB

The last submitted patch, 5: user_edit_form_status-2513576-5-test-only.patch, failed testing.

manauwarsheikh’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +SrijanSprintNight
FileSize
27.59 KB

What: Verified for Blocked user's status.
Result: "Blocked" status is appearing for the blocked user)screenshot attached).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Nice test coverage.

+++ b/core/modules/user/src/AccountForm.php
@@ -200,7 +200,10 @@ public function form(array $form, FormStateInterface $form_state) {
-      '#default_value' => $status,
+      // Convert status to an integer is needed because the value FALSE means
+      // that the radio button is not 'checked'.
+      // @see \Drupal\Core\Render\Element\Radios::processRadios()
+      '#default_value' => (int) $status,

I think rather than doing the cast to int we should just use $account->get('status') instead of $account->isActive().

    if ($admin) {
      $status = $account->isActive();
    }
    else {
      $status = $register ? $config->get('register') == USER_REGISTER_VISITORS : $account->isActive();
    }

That way if the status system is extended by contrib to have other values they need to change less.

willzyx’s picture

Status: Needs work » Needs review
FileSize
2.12 KB

Addressing #8 but I don't think it is a real improvement. I think that if we want to allow contrib modules to extend status system in a comfortable way we should add getter and setter methods for status in user entity and create constants for active and blocked statuses. Currently we use (at least in AccountForm) a fragile (positional) logic for the management of this attribute

    $form['account']['status'] = array(
      '#type' => 'radios',
      '#title' => $this->t('Status'),
      '#default_value' => $status,
      '#options' => array($this->t('Blocked'), $this->t('Active')),<---POSITIONAL
      '#access' => $admin,
    );

Status: Needs review » Needs work

The last submitted patch, 9: user_edit_form_status-2513576-9.patch, failed testing.

willzyx’s picture

Status: Needs work » Needs review

failures seem unrelated to this issue, retesting

googletorp’s picture

Status: Needs review » Reviewed & tested by the community

The patch looks good. It has

• A failing test only patch
• A combined patch that fixes the test
• Code is clean and all is good.

googletorp’s picture

Issue summary: View changes

Add beta evaluation.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed efeb597 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation.

  • alexpott committed efeb597 on 8.0.x
    Issue #2513576 by willzyx, manauwarsheikh, zakir.gori, masipila: User...

Status: Fixed » Closed (fixed)

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