You are here

public static function EntityLegalDocumentVersion::baseFieldDefinitions in Entity Legal 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Entity/EntityLegalDocumentVersion.php \Drupal\entity_legal\Entity\EntityLegalDocumentVersion::baseFieldDefinitions()
  2. 4.0.x src/Entity/EntityLegalDocumentVersion.php \Drupal\entity_legal\Entity\EntityLegalDocumentVersion::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/EntityLegalDocumentVersion.php, line 57

Class

EntityLegalDocumentVersion
Defines the entity legal document version entity.

Namespace

Drupal\entity_legal\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The entity ID of this document.'))
    ->setReadOnly(TRUE)
    ->setSetting('max_length', 64)
    ->setSetting('unsigned', TRUE)
    ->setDefaultValueCallback('Drupal\\entity_legal\\Entity\\EntityLegalDocumentVersion::getDefaultName');
  $fields['published'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Published'))
    ->setDescription(t('If this is the published version of the legal document.'))
    ->setRequired(TRUE)
    ->setDefaultValue(FALSE)
    ->setCardinality(1)
    ->setConstraints([
    'SingleLegalDocumentPublishedVersion' => [],
  ])
    ->setInitialValue(FALSE);
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language'))
    ->setDescription(t('The document version language code.'))
    ->setTranslatable(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The entity UUID of this document'))
    ->setReadOnly(TRUE);
  $fields['document_name'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Form ID'))
    ->setDescription(t('The name of the document this version is bound to.'))
    ->setSetting('target_type', ENTITY_LEGAL_DOCUMENT_ENTITY_NAME)
    ->setRequired(TRUE);
  $fields['label'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Label'))
    ->setDescription(t('The title of the document.'))
    ->setTranslatable(TRUE)
    ->setRequired(TRUE);
  $fields['acceptance_label'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Acceptance label'))
    ->setTranslatable(TRUE)
    ->setRequired(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The date the document was created.'))
    ->setTranslatable(TRUE)
    ->setRequired(TRUE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The date the document was changed.'))
    ->setTranslatable(TRUE)
    ->setRequired(TRUE);
  return $fields;
}