You are here

public static function Registration::baseFieldDefinitions in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Registration.php \Drupal\rng\Entity\Registration::baseFieldDefinitions()
  2. 3.x src/Entity/Registration.php \Drupal\rng\Entity\Registration::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/Registration.php, line 289

Class

Registration
Defines the registration entity class.

Namespace

Drupal\rng\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Registration ID'))
    ->setDescription(t('The registration ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The registration UUID.'))
    ->setReadOnly(TRUE);
  $fields['vid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Revision ID'))
    ->setDescription(t('The registration revision ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(new TranslatableMarkup('Confirmed'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'settings' => [
      'display_label' => TRUE,
    ],
    'weight' => 90,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['type'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Type'))
    ->setDescription(t('The registration type.'))
    ->setSetting('target_type', 'registration_type')
    ->setReadOnly(TRUE);
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language code'))
    ->setDescription(t('The registration language code.'))
    ->setRevisionable(TRUE);
  $fields['event'] = BaseFieldDefinition::create('dynamic_entity_reference')
    ->setLabel(t('Event'))
    ->setDescription(t('The event for the registration.'))
    ->setSetting('exclude_entity_types', 'true')
    ->setSetting('entity_type_ids', [
    'registrant',
    'registration',
  ])
    ->setDescription(t('The relationship between this registration and an event.'))
    ->setRevisionable(TRUE)
    ->setReadOnly(TRUE);
  $fields['groups'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Groups'))
    ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
    ->setDescription(t('The groups the registration is assigned.'))
    ->setSetting('target_type', 'registration_group')
    ->addConstraint('RegistrationGroupSibling');
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Authored on'))
    ->setDescription(t('Time the Registration was created.'))
    ->setTranslatable(FALSE)
    ->setRevisionable(FALSE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Updated on'))
    ->setDescription(t('The time Registration was last updated.'))
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Owner'))
    ->setDescription(t('The owner of the registration.'))
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setDefaultValueCallback('Drupal\\rng\\Entity\\Registration::getCurrentUserId')
    ->setTranslatable(TRUE)
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'weight' => 5,
  ])
    ->setDisplayConfigurable('form', TRUE);

  /**
   * Optional registrant qty field, used for rendering the registrant form. If
   * set and not zero, users cannot add more than this number of registrants
   * to the registration.
   */
  $fields['registrant_qty'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Registrant Qty'))
    ->setDescription(t('Number of registrants on this registration'))
    ->setDefaultValue(0)
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE)
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE);
  return $fields;
}