You are here

public static function FormAssemblyEntity::baseFieldDefinitions in FormAssembly 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/FormAssemblyEntity.php, line 153

Class

FormAssemblyEntity
Defines the FormAssembly Form entity.

Namespace

Drupal\formassembly\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The name of the FormAssembly Form as it is keyed by FormAssembly. Will be overwritten on sync if it is changed in Drupal.'))
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Status'))
    ->setDescription(t('A boolean indicating if the form is enabled.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE)
    ->setInitialValue(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'settings' => [
      'display_label' => TRUE,
    ],
    'weight' => 100,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setTranslatable(FALSE)
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'));
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setTranslatable(FALSE)
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the entity was last edited in Drupal.'));
  $fields['faid'] = BaseFieldDefinition::create('integer')
    ->setTranslatable(FALSE)
    ->setLabel(t('FormAssembly ID'))
    ->setDescription(t('Unique key assigned by FormAssembly to identify each form'))
    ->setReadOnly(TRUE);
  $fields['modified'] = BaseFieldDefinition::create('timestamp')
    ->setTranslatable(FALSE)
    ->setLabel(t('Modified in FormAssembly'))
    ->setDescription(t('The timestamp this form was last changed in FormAssembly.'))
    ->setDisplayOptions('view', [
    'region' => 'hidden',
  ])
    ->setDisplayConfigurable('view', FALSE)
    ->setReadOnly(TRUE);
  $fields['query_params'] = BaseFieldDefinition::create('map')
    ->setLabel(t('Query Parameters'))
    ->setDisplayOptions('view', [
    'region' => 'hidden',
  ])
    ->setDisplayOptions('form', [
    'type' => 'map_assoc_widget',
    'region' => 'content',
    'settings' => [
      'size' => '40',
      'key_placeholder' => 'The tfa identifier',
      'value_placeholder' => 'Pre-filled value',
    ],
    'weight' => 90,
  ])
    ->setTranslatable(FALSE)
    ->setDescription('Enter parameters to be added to FormAssembly form request.<br />' . 'The <em>tfa indentifier</em> string is the name property on the field\'s input tag.')
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', FALSE);
  return $fields;
}