public static function Workflow::baseFieldDefinitions in Forms Steps 8
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/ Workflow.php, line 85
Class
- Workflow
- Defines the Workflow entity.
Namespace
Drupal\forms_steps\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
// Standard field, used as unique if primary index.
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Workflow entity.'))
->setReadOnly(TRUE);
// Standard field, unique outside of the scope of the current project.
$fields['instance_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Instance ID'))
->setDescription(t('The Instance ID of the Workflow entity.'))
->setReadOnly(TRUE);
$fields['entity_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Entity Type'))
->setDescription(t('The Entity Type of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['bundle'] = BaseFieldDefinition::create('string')
->setLabel(t('Bundle'))
->setDescription(t('The Bundle of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['entity_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Entity ID'))
->setDescription(t('The ID of the entity id.'))
->setReadOnly(FALSE);
$fields['form_mode'] = BaseFieldDefinition::create('string')
->setLabel(t('Form Mode'))
->setDescription(t('The Form Mode of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['forms_steps'] = BaseFieldDefinition::create('string')
->setLabel(t('Forms Steps'))
->setDescription(t('The Workflow machine name of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['step'] = BaseFieldDefinition::create('string')
->setLabel(t('Step'))
->setDescription(t('The Step of the Workflow entity.'))
->setReadOnly(FALSE);
// Owner field of the workflow instance.
// Entity reference field, holds the reference to the user object.
// The view shows the user name field of the user.
// The form presents a auto complete field for the user name.
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User Name'))
->setDescription(t('The Name of the associated user.'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'entity_reference',
'weight' => -3,
]);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of inventory entity.'));
$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;
}