You are here

public static function ScheduledTransition::baseFieldDefinitions in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/Entity/ScheduledTransition.php \Drupal\scheduled_transitions\Entity\ScheduledTransition::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/ScheduledTransition.php, line 68

Class

ScheduledTransition
Scheduled Transition entity.

Namespace

Drupal\scheduled_transitions\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) : array {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['entity'] = BaseFieldDefinition::create('dynamic_entity_reference')
    ->setLabel(\t('Entity'))
    ->setDescription(\t('The entity this scheduled transition is for.'))
    ->setRequired(TRUE)
    ->setCardinality(1);

  // Only supports entities with integer IDs.
  $fields['entity_revision_id'] = BaseFieldDefinition::create('integer')
    ->setLabel(\t('Content entity revision ID'))
    ->setDescription(\t('The revision ID of the entity this scheduled transition is for.'))
    ->setRequired(TRUE)
    ->setCardinality(1);
  $fields['entity_revision_langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(\t('Content entity revision language'))
    ->setDescription(\t('The revision language of the entity this scheduled transition is for.'))
    ->setRequired(FALSE)
    ->setCardinality(1);
  $fields['author'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(\t('Authored by'))
    ->setDescription(\t('The user who initiated the scheduled transition.'))
    ->setSetting('target_type', 'user');

  // Workflow is recorded so scheduled transitions can be cleaned up if they
  // are deleted. Similar to 'bundle' column on field tables.
  $fields['workflow'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(\t('Workflow'))
    ->setDescription(\t('The workflow of the state.'))
    ->setSetting('target_type', 'workflow')
    ->setRequired(TRUE);
  $fields['moderation_state'] = BaseFieldDefinition::create('string')
    ->setLabel(\t('Moderation state'))
    ->setDescription(\t('The new state of the content.'))
    ->setRequired(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(\t('Authored on'))
    ->setDescription(\t('The time that the scheduled transition was created.'));
  $fields['transition_on'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(\t('Transition on'))
    ->setDescription(\t('The time scheduled transition should happen.'))
    ->setDisplayOptions('form', [
    'type' => 'datetime_timestamp',
    'weight' => 10,
  ]);
  $fields['locked_on'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(\t('Locked on'))
    ->setDescription(\t('The time a job was created to process the transition.'));
  $fields['options'] = BaseFieldDefinition::create('map')
    ->setLabel(t('Options'))
    ->setDescription(t('Arbitrary settings for scheduled transition.'));
  return $fields;
}