You are here

authorization_drupal_roles.module in Authorization 8

File

authorization_drupal_roles/authorization_drupal_roles.module
View source
<?php

declare (strict_types=1);

/**
 * @file
 * Contains authorization_drupal_roles.module.
 */
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function authorization_drupal_roles_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.authorization_drupal_roles') {
    $output = '';
    $output .= '<h3>' . t('About') . '</h3>';
    $output .= '<p>' . t('Create Drupal roles as part of an Authorization workflow.') . '</p>';
    return $output;
  }
}

/**
 * Implements hook_entity_base_field_info().
 */
function authorization_drupal_roles_entity_base_field_info(EntityTypeInterface $entity_type) {
  if ($entity_type
    ->id() === 'user') {
    $fields = [];
    $fields['authorization_drupal_roles_roles'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Roles previously granted to user'))
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    return $fields;
  }
}