You are here

public static function JobItem::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/JobItem.php, line 73

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['tjiid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Job Item ID'))
    ->setDescription(t('The Job Item ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['tjid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Job'))
    ->setDescription(t('The Job.'))
    ->setReadOnly(TRUE)
    ->setSetting('target_type', 'tmgmt_job')
    ->setDefaultValue(0);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The job item UUID.'))
    ->setReadOnly(TRUE);
  $fields['plugin'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Plugin'))
    ->setDescription(t('The plugin of this job item.'))
    ->setSettings(array(
    'max_length' => 255,
  ));
  $fields['item_type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Item Type'))
    ->setDescription(t('The item type of this job item.'))
    ->setSettings(array(
    'max_length' => 255,
  ));
  $fields['item_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Item ID'))
    ->setDescription(t('The item ID of this job item.'))
    ->setSettings(array(
    'max_length' => 255,
  ));
  $fields['data'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Data'))
    ->setDescription(t('The source data'));
  $states = static::getStates();
  $fields['state'] = BaseFieldDefinition::create('list_integer')
    ->setLabel(t('Job item state'))
    ->setDescription(t('The job item state'))
    ->setSetting('allowed_values', $states)
    ->setDefaultValue(static::STATE_INACTIVE);
  $fields['translator_state'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Translator job item state'));
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the job was last edited.'));
  $fields['count_pending'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Pending count'))
    ->setSetting('unsigned', TRUE);
  $fields['count_translated'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Translated count'))
    ->setSetting('unsigned', TRUE);
  $fields['count_reviewed'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Reviewed count'))
    ->setSetting('unsigned', TRUE);
  $fields['count_accepted'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Accepted count'))
    ->setSetting('unsigned', TRUE);
  $fields['word_count'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Word count'))
    ->setSetting('unsigned', TRUE);
  $fields['tags_count'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Tags count'))
    ->setSetting('unsigned', TRUE);
  return $fields;
}