public static function CertificateMapping::baseFieldDefinitions in Certificate 4.x
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 EditorialContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- src/
Entity/ CertificateMapping.php, line 71
Class
- CertificateMapping
- Defines the credit mapping type entity class.
Namespace
Drupal\certificate\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['map_key'] = BaseFieldDefinition::create('list_string')
->setLabel('Type')
->setSetting('allowed_values_function', 'certificate_get_certificate_mappers')
->setDisplayOptions('form', [
'label' => 'above',
'type' => 'options_select',
'weight' => -2,
]);
$fields['map_value'] = BaseFieldDefinition::create('list_string')
->setLabel('Selection')
->setSetting('allowed_values_function', 'certificate_get_certificate_mapper_values')
->setDisplayOptions('form', [
'label' => 'above',
'type' => 'options_select',
'weight' => -1,
]);
$fields['cid'] = BaseFieldDefinition::create('list_string')
->setRequired(TRUE)
->setLabel('Template')
->setSetting('allowed_values_function', 'certificate_get_certificate_options')
->setDisplayOptions('form', [
'type' => 'options_select',
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setRevisionable(TRUE)
->setLabel('Created');
$fields['changed'] = BaseFieldDefinition::create('changed')
->setRevisionable(TRUE)
->setLabel('Changed');
$fields += parent::baseFieldDefinitions($entity_type);
return $fields;
}