public static function Job::baseFieldDefinitions in Translation Management Tool 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/ Job.php, line 62
Class
- Job
- Entity class for the tmgmt_job entity.
Namespace
Drupal\tmgmt\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['tjid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Job ID'))
->setDescription(t('The Job ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The node UUID.'))
->setReadOnly(TRUE);
$fields['source_language'] = BaseFieldDefinition::create('language')
->setLabel(t('Source language code'))
->setDescription(t('The source language.'));
$fields['target_language'] = BaseFieldDefinition::create('language')
->setLabel(t('Target language code'))
->setDescription(t('The target language.'));
$fields['label'] = BaseFieldDefinition::create('string')
->setLabel(t('Label'))
->setDescription(t('The label of this job.'))
->setDefaultValue('')
->setSettings(array(
'max_length' => 255,
))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => -5,
))
->setDisplayConfigurable('form', TRUE);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Owner'))
->setDescription(t('The user that is the job owner.'))
->setSettings(array(
'target_type' => 'user',
))
->setDefaultValue(0);
$fields['translator'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Provider'))
->setDescription(t('The selected provider'))
->setSettings(array(
'target_type' => 'tmgmt_translator',
));
$fields['settings'] = BaseFieldDefinition::create('map')
->setLabel(t('Settings'))
->setDescription(t('Provider specific configuration and context information for this job.'))
->setDefaultValue(array());
$fields['reference'] = BaseFieldDefinition::create('string')
->setLabel(t('Reference'))
->setDescription(t('Remote reference of this job'))
->setDefaultValue('')
->setSettings(array(
'max_length' => 255,
));
$fields['state'] = BaseFieldDefinition::create('list_integer')
->setLabel(t('Job state'))
->setDescription(t('The job state.'))
->setSetting('allowed_values', Job::getStates())
->setDefaultValue(Job::STATE_UNPROCESSED);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the job was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the job was last edited.'));
$fields['job_type'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Job type'))
->setDescription(t('Type of job entity, can be Normal or Continuous.'))
->setSetting('allowed_values', [
static::TYPE_NORMAL,
static::TYPE_CONTINUOUS,
])
->setDefaultValue(static::TYPE_NORMAL);
$fields['continuous_settings'] = BaseFieldDefinition::create('map')
->setLabel(t('Continuous settings'))
->setDescription(t('Continuous sources configuration.'))
->setDefaultValue(array());
return $fields;
}