You are here

public static function WorkflowTransition::baseFieldDefinitions in Workflow 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()

1 call to WorkflowTransition::baseFieldDefinitions()
WorkflowScheduledTransition::baseFieldDefinitions in src/Entity/WorkflowScheduledTransition.php
Define the fields. Modify the parent fields.
1 method overrides WorkflowTransition::baseFieldDefinitions()
WorkflowScheduledTransition::baseFieldDefinitions in src/Entity/WorkflowScheduledTransition.php
Define the fields. Modify the parent fields.

File

src/Entity/WorkflowTransition.php, line 912

Class

WorkflowTransition
Implements an actual, executed, Transition.

Namespace

Drupal\workflow\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = [];
  $fields['hid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Transition ID'))
    ->setDescription(t('The transition ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);

  //    $fields['wid'] = BaseFieldDefinition::create('string')
  $fields['wid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Workflow Type'))
    ->setDescription(t('The workflow type the transition relates to.'))
    ->setSetting('target_type', 'workflow_type')
    ->setRequired(TRUE)
    ->setTranslatable(FALSE)
    ->setRevisionable(FALSE);
  $fields['entity_type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Entity type'))
    ->setDescription(t('The Entity type this transition belongs to.'))
    ->setSetting('is_ascii', TRUE)
    ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH)
    ->setReadOnly(TRUE);
  $fields['entity_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Entity ID'))
    ->setDescription(t('The Entity ID this record is for.'))
    ->setRequired(TRUE)
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['revision_id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Revision ID'))
    ->setDescription(t('The current version identifier.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['field_name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Field name'))
    ->setDescription(t('The name of the field the transition relates to.'))
    ->setRequired(TRUE)
    ->setTranslatable(FALSE)
    ->setRevisionable(FALSE)
    ->setSetting('max_length', 32);
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language'))
    ->setDescription(t('The entity language code.'))
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'region' => 'hidden',
  ])
    ->setDisplayOptions('form', [
    'type' => 'language_select',
    'weight' => 2,
  ]);
  $fields['delta'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Delta'))
    ->setDescription(t('The sequence number for this data item, used for multi-value fields.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['from_sid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('From state'))
    ->setDescription(t('The {workflow_states}.sid the entity started as.'))
    ->setSetting('target_type', 'workflow_state')
    ->setReadOnly(TRUE);
  $fields['to_sid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('To state'))
    ->setDescription(t('The {workflow_states}.sid the entity transitioned to.'))
    ->setSetting('target_type', 'workflow_state')
    ->setReadOnly(TRUE);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('User ID'))
    ->setDescription(t('The user ID of the transition author.'))
    ->setTranslatable(TRUE)
    ->setSetting('target_type', 'user')
    ->setDefaultValue(0)
    ->setRevisionable(TRUE);
  $fields['timestamp'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Timestamp'))
    ->setDescription(t('The time that the current transition was executed.'))
    ->setRevisionable(TRUE);
  $fields['comment'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Log message'))
    ->setDescription(t('The comment explaining this transition.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE);
  return $fields;
}