Drupal Roles Consumer - store mappings in user.data

Created on 7 November 2023, 4 months ago
Updated 13 February 2024, 12 days 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 https://api.contrib.social 0.61.6-2-g546bc20