Drupal Roles Consumer - store mappings in user.data

Created on 7 November 2023, about 1 year ago
Updated 9 September 2024, 3 months ago

Problem/Motivation

The mapped roles are stored in a field on the user. Only one profile can revoke roles correctly.

Steps to reproduce

Proposed resolution

Use the user.data service to store the mappings. This will allow every profile to revoke roles previously granted correctly.

$user = \Drupal::currentUser();

// Define an array of role => profile.
$roles= [
  'administrator' => 'profile_a',
  'teacher' => 'profile_b',
  'staff' => 'profile_b',
];

// Store the array as user data.
\Drupal::service('user.data')->set('authorization_drupal_roles', $user->id(), 'roles', $roles);

Remaining tasks

Update existing code to use user.data.

Write hook_update_N function to store the users existing roles.

Remove 'authorization_drupal_roles_roles' field.

User interface changes

API changes

Data model changes

The 'authorization_drupal_roles_roles' field will be removed from the user.

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bluegeek9

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024