You are here

function role_delegation_entity_base_field_info in Role Delegation 8

Implements hook_entity_base_field_info().

File

./role_delegation.module, line 176
Allows admins to grant roles the authority to assign selected roles to users.

Code

function role_delegation_entity_base_field_info(EntityTypeInterface $entity_type) {
  $fields = [];
  if ($entity_type
    ->id() === 'user') {
    $fields['role_change'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Roles'))
      ->setSetting('target_type', 'user_role')
      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
      ->setComputed(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 1,
    ])
      ->setSetting('handler', 'role_change:user_role')
      ->setDefaultValue(DelegatableRoles::$emptyFieldValue);
  }
  return $fields;
}