You are here

public static function YamlFormSubmission::baseFieldDefinitions in YAML Form 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/YamlFormSubmission.php, line 94

Class

YamlFormSubmission
Defines the YamlFormSubmission entity.

Namespace

Drupal\yamlform\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['serial'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Serial number'))
    ->setDescription(t('The serial number of the form submission entity.'))
    ->setReadOnly(TRUE);
  $fields['sid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Submission ID'))
    ->setDescription(t('The ID of the form submission entity.'))
    ->setReadOnly(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('Submission UUID'))
    ->setDescription(t('The UUID of the form submission entity.'))
    ->setReadOnly(TRUE);
  $fields['token'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Token'))
    ->setDescription(t('A secure token used to look up a submission.'))
    ->setSetting('max_length', 255)
    ->setReadOnly(TRUE);
  $fields['uri'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Submission URI'))
    ->setDescription(t('The URI the user submitted the form.'))
    ->setSetting('max_length', 2000)
    ->setReadOnly(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the form submission was first saved as draft or submitted.'));
  $fields['completed'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Completed'))
    ->setDescription(t('The time that the form submission was submitted as complete (not draft).'));
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the form submission was last saved (complete or draft).'));
  $fields['in_draft'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Is draft'))
    ->setDescription(t('Is this a draft of the submission?'))
    ->setDefaultValue(FALSE);
  $fields['current_page'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Current page'))
    ->setDescription(t('The current wizard page.'))
    ->setSetting('max_length', 128);
  $fields['remote_addr'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Remote IP address'))
    ->setDescription(t('The IP address of the user that submitted the form.'))
    ->setSetting('max_length', 128);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Submitted by'))
    ->setDescription(t('The submitter.'))
    ->setSetting('target_type', 'user');
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language'))
    ->setDescription(t('The submission language code.'));
  $fields['yamlform_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Form'))
    ->setDescription(t('The associated yamlform.'))
    ->setSetting('target_type', 'yamlform');
  $fields['entity_type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Submitted to: Entity type'))
    ->setDescription(t('The entity type to which this submission was submitted from.'))
    ->setSetting('is_ascii', TRUE)
    ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);

  // Can't use entity reference without a target type because it defaults to
  // an integer which limits reference to only content entities (and not
  // config entities like Views, Panels, etc...).
  // @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::propertyDefinitions()
  $fields['entity_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Submitted to: Entity ID'))
    ->setDescription(t('The ID of the entity of which this form submission was submitted from.'))
    ->setSetting('max_length', 255);
  $fields['sticky'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Sticky'))
    ->setDescription(t('A flag that indicate the status of the form submission.'))
    ->setDefaultValue(FALSE);
  $fields['notes'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Notes'))
    ->setDescription(t('Administrative notes about the form submission.'))
    ->setDefaultValue('');
  return $fields;
}