Untitled

 avatar
unknown
plain_text
5 months ago
1.0 kB
4
Indexable
/**
 * Implements hook_permission_alter().
 */
function site_manager_permissions_permission_alter(array &$permissions) {
  // Optionally, you can define new permissions here if needed.
}

/**
 * Implements hook_user_access_alter().
 *
 * Dynamically alter user permissions based on profile tags.
 */
function site_manager_permissions_user_access_alter(array &$permissions, \Drupal\Core\Session\AccountInterface $account) {
  // Only alter permissions for Site Manager role.
  if ($account->hasRole('site_manager')) {
    // Load the user's profile tag field.
    $profile_tag = $account->get('field_profile_tag')->value; // Replace 'field_profile_tag' with the actual field name.

    // Check if the profile tag matches "site1".
    if ($profile_tag !== 'site1') {
      // Remove permissions for editing specific vocabularies.
      $permissions = array_diff($permissions, [
        'edit terms in vocabulary_name_1',
        'delete terms in vocabulary_name_1',
        // Add more permissions as needed.
      ]);
    }
  }
}
Editor is loading...
Leave a Comment