You are here

public static function LocalTask::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

translators/tmgmt_local/src/Entity/LocalTask.php, line 58

Class

LocalTask
Entity class for the local task entity.

Namespace

Drupal\tmgmt_local\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['tltid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Local task ID'))
    ->setDescription(t('The local task ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['tjid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Job'))
    ->setDescription(t('The Job for this task.'))
    ->setReadOnly(TRUE)
    ->setSetting('target_type', 'tmgmt_job')
    ->setDefaultValue(0);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The node UUID.'))
    ->setReadOnly(TRUE);
  $fields['title'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setDescription(t('The title of this local task.'))
    ->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 created the local task.'))
    ->setSettings(array(
    'target_type' => 'user',
  ))
    ->setDefaultValue(0);
  $fields['tuid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Assigned user'))
    ->setDescription(t('The user assigned to this task.'))
    ->setSettings(array(
    'target_type' => 'user',
  ))
    ->setDefaultValue(0);
  $fields['status'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Status'))
    ->setDescription(t('The local task status.'))
    ->setDefaultValue(static::STATUS_UNASSIGNED);
  $fields['loop_count'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Loop count'))
    ->setDescription(t('Counter for how many times task was returned to the assigned user.'))
    ->setDefaultValue(static::STATUS_UNASSIGNED);
  $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.'));
  return $fields;
}