public static function Contributor::baseFieldDefinitions in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_entity/src/Entity/Contributor.php \Drupal\bibcite_entity\Entity\Contributor::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
- modules/
bibcite_entity/ src/ Entity/ Contributor.php, line 220
Class
- Contributor
- Defines the Contributor entity.
Namespace
Drupal\bibcite_entity\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setComputed(TRUE)
->setReadOnly(FALSE)
->setCustomStorage(TRUE)
->setClass('\\Drupal\\bibcite_entity\\ContributorName')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'type' => 'bibcite_parse_name',
'weight' => 0,
]);
$fields['leading_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Leading initial'))
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 1,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 2,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['prefix'] = BaseFieldDefinition::create('string')
->setLabel(t('Prefix'))
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 2,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 3,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['first_name'] = BaseFieldDefinition::create('string')
->setLabel(t('First name'))
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 3,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['middle_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Middle name'))
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 4,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 5,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['last_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Last name'))
->setDefaultValue('')
->setRequired(TRUE)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 5,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 6,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['nick'] = BaseFieldDefinition::create('string')
->setLabel(t('Nickname'))
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 6,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 7,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['suffix'] = BaseFieldDefinition::create('string')
->setLabel(t('Suffix'))
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 7,
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 8,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}