You are here

function simple_oauth_entity_base_field_info in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.4 simple_oauth.module \simple_oauth_entity_base_field_info()
  2. 5.x simple_oauth.module \simple_oauth_entity_base_field_info()

Implements hook_entity_base_field_info().

File

./simple_oauth.module, line 55
Contains simple_oauth.module..

Code

function simple_oauth_entity_base_field_info(EntityTypeInterface $entity_type) {
  $fields = [];
  if ($entity_type
    ->id() == 'consumer') {
    $fields['secret'] = BaseFieldDefinition::create('password')
      ->setLabel(new TranslatableMarkup('Secret'))
      ->setDescription(new TranslatableMarkup('The secret key of this client (hashed).'));
    $fields['confidential'] = BaseFieldDefinition::create('boolean')
      ->setLabel(new TranslatableMarkup('Is Confidential?'))
      ->setDescription(new TranslatableMarkup('A boolean indicating whether the client secret needs to be validated or not.'))
      ->setDisplayOptions('view', [
      'label' => 'inline',
      'type' => 'boolean',
      'weight' => 3,
    ])
      ->setDisplayOptions('form', [
      'weight' => 3,
    ])
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(TRUE);
    $fields['roles'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(new TranslatableMarkup('Scopes'))
      ->setDescription(new TranslatableMarkup('The roles for this Consumer. OAuth2 scopes are implemented as Drupal roles.'))
      ->setRevisionable(TRUE)
      ->setSetting('target_type', 'user_role')
      ->setSetting('handler', 'default')
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
      ->setTranslatable(FALSE)
      ->setDisplayOptions('view', [
      'label' => 'inline',
      'type' => 'entity_reference_label',
      'weight' => 5,
    ])
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 5,
    ]);
  }
  return $fields;
}