Problem/Motivation

The RoleAssign with User CSV Import submodule should alter the User CSV Import import form to restrict the available options to the ones set by the RoleAssign module.

Currently with User CSV Import, RoleAssign and RoleAssign with User CSV Import modules enabled and configured, the User CSV Import import form is not showing any role options and the upload is failing because a role option is not set.

This is happening because:

  • The configuration settings from the RoleAssign are outputting an indexed array.
  • The role options array within the User CSV Import import form is an associative array.
  • The current code is outputting an empty array when trying to intersect these arrays.
  if ($form_id == 'user_csv_import_form') {
    // limit the visible roles to just those saved in roleassign.settings
    $form['config_options']['roles']['#options'] =
      array_intersect_key(
        $form['config_options']['roles']['#options'],
        array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles')
      )
    );
  }

Steps to reproduce

  1. Install, enable and configure:
    • "drupal/roleassign": "^2.0"
    • "drupal/user_csv_import": "^2.0"
  2. Install and configure RoleAssign with User CSV Import
  3. .

  4. Go to /admin/people/import and attempt to upload a CSV.

Proposed resolution

Fix the logic (and add some extra conditional logic) as follows:

if ($form_id == 'user_csv_import_form') {
      $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles'));
      if ((!empty($assignable_roles) && is_array($assignable_roles))) {
          $form['config_options']['roles']['#options'] =
              array_intersect_key(
                  $form['config_options']['roles']['#options'],
                  array_flip($assignable_roles)
              );
      }
}

Remaining tasks

Do it.

User interface changes

Role options shall display.

Comments

iarla created an issue. See original summary.

iarla’s picture

Issue summary: View changes
iarla’s picture

iarla’s picture

iarla’s picture

gisle’s picture

Assigned: iarla » Unassigned
Status: Active » Needs review

The patch in comment #4 needs to be reviewed by some using User CSV Import along with RoleAssign with User CSV Import.

  • iarla authored a06ea913 on 2.0.x
    Issue #3384659 by iarla, gisle:: Fixed RoleAssign with User CSV Import...
gisle’s picture

Status: Needs review » Fixed

This is now committed to the latest 2.0.x-dev snapshot.

Status: Fixed » Closed (fixed)

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