public static function ScheduledUpdate::baseFieldDefinitions in Scheduled Updates 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/ ScheduledUpdate.php, line 131 - Contains \Drupal\scheduled_updates\Entity\ScheduledUpdate.
Class
- ScheduledUpdate
- Defines the Scheduled update entity.
Namespace
Drupal\scheduled_updates\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Scheduled update entity.'))
->setReadOnly(TRUE);
$fields['type'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The Scheduled update type/bundle.'))
->setSetting('target_type', 'scheduled_update_type')
->setRequired(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Scheduled update entity.'))
->setReadOnly(TRUE);
$status_options = [
ScheduledUpdateInterface::STATUS_UNRUN => 'Un-run',
ScheduledUpdateInterface::STATUS_INQUEUE => 'In Queue',
ScheduledUpdateInterface::STATUS_REQUEUED => 'Re-queued',
ScheduledUpdateInterface::STATUS_SUCCESSFUL => 'Successful',
ScheduledUpdateInterface::STATUS_UNSUCESSFUL => 'Un-successful',
ScheduledUpdateInterface::STATUS_INACTIVE => 'Inactive',
];
$fields['status'] = BaseFieldDefinition::create('list_integer')
->setLabel(t('Status'))
->setDescription(t('The status of the update.'))
->setDefaultValue(ScheduledUpdateInterface::STATUS_UNRUN)
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'list_default',
'weight' => -100,
])
->setSetting('allowed_values', $status_options);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Created by'))
->setDescription(t('The user ID of author of the Scheduled update entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\\scheduled_updates\\Entity\\ScheduledUpdate::getCurrentUserId')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'author',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code for the Scheduled update 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.'));
$fields['update_timestamp'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Update Date/time'))
->setDescription(t('The time that the update will happen.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setRequired(TRUE)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'timestamp',
'weight' => 10,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => -9,
])
->setDisplayConfigurable('form', TRUE);
$fields['entity_ids'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Entities to Update'))
->setDescription(t('The entities that will be updated.'))
->setRequired(TRUE)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}