You are here

public static function FillPdfFormField::baseFieldDefinitions in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x src/Entity/FillPdfFormField.php \Drupal\fillpdf\Entity\FillPdfFormField::baseFieldDefinitions()

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/FillPdfFormField.php, line 40

Class

FillPdfFormField
Defines an entity for PDF fields associated with a FillPDF form entity.

Namespace

Drupal\fillpdf\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = [];
  $fields['ffid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('FillPDF Form Field ID'))
    ->setDescription(t('The ID of the FillPdfFormField entity.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['fillpdf_form'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('FillPDF Form ID'))
    ->setDescription(t('The ID of the FillPdfFormField entity.'))
    ->setSetting('target_type', 'fillpdf_form');
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the FillPdfFormField entity.'))
    ->setReadOnly(TRUE);
  $fields['pdf_key'] = BaseFieldDefinition::create('string')
    ->setLabel(t('PDF Key'))
    ->setDescription(t('The name of the field in the PDF form.'));
  $fields['label'] = BaseFieldDefinition::create('string')
    ->setLabel(t('PDF field label'))
    ->setDescription(t('An optional label to help you identify the field.'))
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => 0,
  ]);
  $fields['prefix'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Text before field value'))
    ->setDescription(t('Text to add to the front of the field value unless the field value is blank.'))
    ->setDisplayOptions('form', [
    'type' => 'string_long',
    'weight' => 0,
  ]);
  $fields['value'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Fill pattern'))
    ->setDescription(t('Text and tokens with which to fill in the PDF. This field supports tokens.'))
    ->setDisplayOptions('form', [
    'type' => 'string_long',
    'weight' => 0,
  ]);
  $fields['suffix'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Text after field value'))
    ->setDescription(t('Text to add to the end of the field value unless the field value is blank.'))
    ->setDisplayOptions('form', [
    'type' => 'string_long',
    'weight' => 0,
  ]);
  $fields['replacements'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Change text before sending to PDF (Transform values)'))
    ->setDescription(FillPdfAdminFormHelper::getReplacementsDescription())
    ->setDisplayOptions('form', [
    'type' => 'string_long',
    'weight' => 0,
  ]);
  return $fields;
}