You are here

public static function Replication::baseFieldDefinitions in Workspace 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/Replication.php, line 82

Class

Replication
Defines the Replication entity.

Namespace

Drupal\workspace\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Replication entity.'))
    ->setReadOnly(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Replication entity.'))
    ->setReadOnly(TRUE);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Created by'))
    ->setDescription(t('The user ID of person who started the deployment.'))
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setDefaultValueCallback('Drupal\\workspace\\Entity\\Replication::getCurrentUserId');
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setRequired(TRUE)
    ->setSettings([
    'max_length' => 512,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'string',
    'weight' => -4,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -4,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['description'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Description'))
    ->setSettings([
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => -3,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => -3,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['source'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Source'))
    ->setDescription(t('The source endpoint.'))
    ->setRequired(TRUE)
    ->setSetting('target_type', 'workspace_pointer')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => -2,
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => -2,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['target'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Target'))
    ->setDescription(t('The target endpoint.'))
    ->setRequired(TRUE)
    ->setSetting('target_type', 'workspace_pointer')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => -1,
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => -1,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['replicated'] = BaseFieldDefinition::create('datetime')
    ->setLabel(t('Deployed'))
    ->setDescription(t('The time that the entity was deployed.'));
  $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['replication_status'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Replication status'))
    ->setDescription(t('The status of the replication.'))
    ->setRequired(TRUE)
    ->setDefaultValue(static::FAILED)
    ->setInitialValue(static::FAILED);
  $fields['fail_info'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Replication fail info'))
    ->setDescription(t('When a replication fails, it contains the info about the cause of the fail.'))
    ->setRequired(FALSE)
    ->setDefaultValue('')
    ->setInitialValue('');
  $fields['archive_source'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Archive source workspace flag'))
    ->setDescription(t('The flag that marks if the source workspace should be archived if replication ends with success.'))
    ->setRequired(FALSE)
    ->setDefaultValue(FALSE)
    ->setInitialValue(FALSE);
  $fields['doc_ids'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Selected entity UUIDs for deployment'))
    ->setDescription(t('This filed contains the list of UUIDs for changed entities selected for this replication.'))
    ->setRequired(FALSE)
    ->setDefaultValue('')
    ->setInitialValue('')
    ->setSetting('case_sensitive', TRUE);
  return $fields;
}