You are here

public static function OpignoCertificate::baseFieldDefinitions in Opigno certificate 8

Same name and namespace in other branches
  1. 3.x src/Entity/OpignoCertificate.php \Drupal\opigno_certificate\Entity\OpignoCertificate::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 EditorialContentEntityBase::baseFieldDefinitions

See also

\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()

\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()

File

src/Entity/OpignoCertificate.php, line 200

Class

OpignoCertificate
Defines the opigno_certificate entity class.

Namespace

Drupal\opigno_certificate\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['label'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Label'))
    ->setRequired(TRUE)
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE)
    ->setSetting('max_length', 255)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -6,
  ])
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayConfigurable('form', TRUE);
  $fields['paper_orientation'] = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Paper Orientation'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue('portrait')
    ->setSetting('allowed_values', [
    'portrait' => t('Portrait'),
    'landscape' => t('Landscape'),
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => -5,
  ]);
  $fields['referencing_entity'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Referencing entity'))
    ->setComputed(TRUE)
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The username of the opigno_certificate author.'))
    ->setRequired(TRUE)
    ->setRevisionable(TRUE)
    ->setSetting('target_type', 'user')
    ->setDefaultValueCallback('Drupal\\opigno_certificate\\Entity\\OpignoCertificate::getCurrentUserId')
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'author',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'weight' => 5,
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'placeholder' => '',
    ],
  ])
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayConfigurable('form', TRUE);
  $fields['status']
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'settings' => [
      'display_label' => TRUE,
    ],
    'weight' => 120,
  ])
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayConfigurable('form', TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Authored on'))
    ->setDescription(t('The time that the opigno_certificate was created.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'timestamp',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'datetime_timestamp',
    'weight' => 10,
  ])
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayConfigurable('form', TRUE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the certificate was last edited.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE);
  return $fields;
}