On user creating I get:

Notice: Undefined variable: assigned_roles in roleassign_form_alter() (line 109 of modules/contrib/roleassign/roleassign.module).
Warning: array_keys() expects parameter 1 to be array, null given in roleassign_form_alter() (line 109 of modules/contrib/roleassign/roleassign.module).
Warning: Invalid argument supplied for foreach() in Drupal\Core\Render\Element\Checkboxes::valueCallback() (line 105 of core/lib/Drupal/Core/Render/Element/Checkboxes.php).

Looking on the code i see that he is trying to set default based on assigned_roles:

   $roles_field = array(
     '#type' => 'checkboxes',
     '#title' => t('Assignable roles'),
     '#options' => $assignable_roles,
     '#default_value' => array_keys($assigned_roles),
     '#description' => t('The user receives the combined permissions of all roles selected here and the following roles: %roles.', array('%roles' => implode('$
    );

Are these asigned roles the user assigned roles? The user im using cannot create an user of the same role.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

diogoviannaaraujo created an issue. See original summary.

svendecabooter’s picture

Status: Active » Needs review
FileSize
766 bytes

Normally this array should at least contain "authenticated user", but presumably there might be cases where that's not true.
Attached is a patch that adds extra checks to avoid these PHP warnings.

salvis’s picture

"authenticated user" should be in $sticky_roles, not in $assigned_roles.

Thanks for the report and the patch!

salvis’s picture

FileSize
763 bytes
+++ b/roleassign.module
@@ -106,7 +106,7 @@ function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id)
+        '#default_value' => is_array($assigned_roles) ? array_keys($assigned_roles) : array(),

Actually, when going to admin/people/create, $assigned_roles is not even assigned — empty() is the test to use.

salvis’s picture

Title: default value getting null on array_keys($assigned_roles) » Avoid uninitialized $assigned_roles variable

Queued for 8 hours? Never mind...

  • salvis committed 032467e on 8.x-1.x
    Issue #2657668 by salvis, svendecabooter: Avoid uninitialized $...
salvis’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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