function simple_oauth_entity_base_field_info in Simple OAuth (OAuth2) & OpenID Connect 5.x
Same name and namespace in other branches
- 8.4 simple_oauth.module \simple_oauth_entity_base_field_info()
- 8.3 simple_oauth.module \simple_oauth_entity_base_field_info()
Implements hook_entity_base_field_info().
File
- ./
simple_oauth.module, line 56 - 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,
]);
$fields['redirect'] = BaseFieldDefinition::create('uri')
->setLabel(new TranslatableMarkup('Redirect URI'))
->setDescription(new TranslatableMarkup('The URI this client will redirect to when needed.'))
->setDisplayOptions('view', [
'label' => 'inline',
'weight' => 4,
])
->setDisplayOptions('form', [
'weight' => 4,
])
->setDisplayConfigurable('view', TRUE)
->setTranslatable(TRUE)
->setSetting('max_length', 255);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(new TranslatableMarkup('User'))
->setDescription(new TranslatableMarkup('When no specific user is authenticated Drupal will use this user as the author of all the actions made.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(FALSE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'entity_reference_label',
'weight' => 1,
])
->setCardinality(1)
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 0,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
]);
$fields['pkce'] = BaseFieldDefinition::create('boolean')
->setLabel(new TranslatableMarkup('Use PKCE?'))
->setDescription(new TranslatableMarkup('A boolean indicating whether the client uses @pkce (e.g., a native client or SPA)'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'boolean',
'weight' => 3,
])
->setDisplayOptions('form', [
'weight' => 3,
])
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDefaultValue(FALSE);
}
return $fields;
}