public static function LtiToolProviderConsumer::baseFieldDefinitions in LTI Tool Provider 8
Same name and namespace in other branches
- 2.x src/Entity/LtiToolProviderConsumer.php \Drupal\lti_tool_provider\Entity\LtiToolProviderConsumer::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/ LtiToolProviderConsumer.php, line 50
Class
- LtiToolProviderConsumer
- Defines the LTIToolProviderConsumer entity.
Namespace
Drupal\lti_tool_provider\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) : array {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['consumer'] = BaseFieldDefinition::create('string')
->setLabel(t('Consumer'))
->setDescription(t('The name of the Consumer entity.'))
->setRequired(true)
->setSettings([
'max_length' => 512,
'text_processing' => 0,
])
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => 1,
])
->setDisplayOptions('form', [
'type' => 'string',
'weight' => 1,
])
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['consumer_key'] = BaseFieldDefinition::create('string')
->setLabel(t('Key'))
->setDescription(t('The key of the Consumer entity.'))
->setRequired(true)
->setSettings([
'max_length' => 512,
'text_processing' => 0,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 2,
])
->setDisplayOptions('form', [
'type' => 'string',
'weight' => 2,
])
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['consumer_secret'] = BaseFieldDefinition::create('string')
->setLabel(t('Secret'))
->setDescription(t('The secret of the Consumer entity.'))
->setRequired(true)
->setSettings([
'max_length' => 512,
'text_processing' => 0,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 3,
])
->setDisplayOptions('form', [
'type' => 'string',
'weight' => 3,
])
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name field'))
->setDescription(t('The LTI field to get the users unique name from. Default is "lis_person_contact_email_primary"'))
->setRequired(true)
->setDefaultValue('lis_person_contact_email_primary')
->setSettings([
'max_length' => 512,
'text_processing' => 0,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 4,
])
->setDisplayOptions('form', [
'type' => 'string',
'weight' => 4,
])
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['mail'] = BaseFieldDefinition::create('string')
->setLabel(t('Mail field'))
->setDescription(t('The LTI field to get the users email from. Default is "lis_person_contact_email_primary"'))
->setRequired(true)
->setDefaultValue('lis_person_contact_email_primary')
->setSettings([
'max_length' => 512,
'text_processing' => 0,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 5,
])
->setDisplayOptions('form', [
'type' => 'string',
'weight' => 5,
])
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Date created'))
->setDescription(t('Date the consumer was created'));
return $fields;
}