public static function Oauth2Token::baseFieldDefinitions in Simple OAuth (OAuth2) & OpenID Connect 5.x
Same name and namespace in other branches
- 8.4 src/Entity/Oauth2Token.php \Drupal\simple_oauth\Entity\Oauth2Token::baseFieldDefinitions()
- 8.2 src/Entity/Oauth2Token.php \Drupal\simple_oauth\Entity\Oauth2Token::baseFieldDefinitions()
- 8.3 src/Entity/Oauth2Token.php \Drupal\simple_oauth\Entity\Oauth2Token::baseFieldDefinitions()
Provides base field definitions for an entity type.
Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'));
By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().
The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.
Overrides ContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- src/
Entity/ Oauth2Token.php, line 51
Class
- Oauth2Token
- Defines the Oauth2 Token entity.
Namespace
Drupal\simple_oauth\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Access Token entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Access Token entity.'))
->setReadOnly(TRUE);
$fields['bundle'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Bundle'))
->setDescription(t('The bundle property.'))
->setRevisionable(FALSE)
->setReadOnly(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'entity_reference_label',
'weight' => 0,
])
->setSetting('target_type', 'oauth2_token_type');
$fields['auth_user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User'))
->setDescription(t('The user ID of the user this access token is authenticating.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback(static::class . '::getDefaultEntityOwner')
->setTranslatable(FALSE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'author',
'weight' => 1,
])
->setCardinality(1)
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 0,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
]);
$fields['client'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Client'))
->setDescription(t('The consumer client for this Access Token.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'consumer')
->setSetting('handler', 'default')
->setTranslatable(FALSE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'entity_reference_label',
'weight' => 2,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 2,
]);
$fields['scopes'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Scopes'))
->setDescription(t('The scopes for this Access Token. 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' => 3,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 3,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
]);
$fields['value'] = BaseFieldDefinition::create('string')
->setLabel(t('Token'))
->setDescription(t('The token value.'))
->setSettings([
'max_length' => 128,
'text_processing' => 0,
])
->setRequired(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => 4,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => 5,
]);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => 6,
]);
$fields['expire'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Expire'))
->setDescription(t('The time when the token expires.'))
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 7,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => 7,
])
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the token is available.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'boolean',
'weight' => 8,
])
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDefaultValue(TRUE);
return $fields;
}