public static function EmailConfirmation::baseFieldDefinitions in Email confirmer 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/ EmailConfirmation.php, line 55
Class
- EmailConfirmation
- Defines the email confirmation entity class.
Namespace
Drupal\email_confirmer\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
$fields = parent::baseFieldDefinitions($entity_type);
$fields['cid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Email confirmation ID'))
->setDescription(t('The ID of the email confirmation.'))
->setReadOnly(TRUE);
$fields['email'] = BaseFieldDefinition::create('email')
->setLabel(t('Email'))
->setDescription(t('The email address of this confirmation.'))
->setRequired(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 0,
]);
$fields['realm'] = BaseFieldDefinition::create('string')
->setLabel(t('Realm'))
->setSetting('max_length', 255)
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 0,
]);
$fields['ip'] = BaseFieldDefinition::create('string')
->setLabel(t('IP address'))
->setDescription(t('Confirmation related IP address.'))
->setSetting('max_length', 45)
->setDefaultValueCallback('Drupal\\email_confirmer\\Entity\\EmailConfirmation::getRequestIp')
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 0,
]);
$fields['data'] = BaseFieldDefinition::create('map')
->setLabel(t('Data'))
->setDescription(t('Any arbitrary data to store with the confirmation.'));
$fields['confirm_url'] = BaseFieldDefinition::create('uri')
->setLabel(t('On confirmation URL'))
->setDescription(t('A URL to go after an email confirmation was done.'))
->setSetting('max_length', 255);
$fields['cancel_url'] = BaseFieldDefinition::create('uri')
->setLabel(t('On cancellation URL'))
->setDescription(t('A URL to go after an email confirmation was cancelled.'))
->setSetting('max_length', 255);
$fields['error_url'] = BaseFieldDefinition::create('uri')
->setLabel(t('On error URL'))
->setDescription(t('A URL to go on email confirmation error.'))
->setSetting('max_length', 255);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID who created the email confirmation.'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\\email_confirmer\\Entity\\EmailConfirmation::getCurrentUserId')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE);
$fields['private'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Private'))
->setDescription(t('A boolean indicating whether the email confirmation is private.'))
->setDefaultValue(EmailConfirmationInterface::IS_PUBLIC)
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 0,
]);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Cancelled'))
->setDescription(t('A boolean indicating whether the email confirmation is cancelled.'))
->setDefaultValue(EmailConfirmationInterface::ACTIVE)
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 0,
]);
$fields['sent'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Last request sent on'))
->setDescription(t('The time the last request was sent.'))
->setDisplayOptions('view', [
'type' => 'timestamp',
'weight' => 0,
]);
$fields['confirmed'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Confirmed'))
->setDescription(t('A boolean indicating whether the email confirmation is confirmed.'))
->setDefaultValue(EmailConfirmationInterface::UNCONFIRMED)
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 0,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Added on'))
->setDefaultValueCallback('Drupal\\email_confirmer\\Entity\\EmailConfirmation::getRequestTime')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
]);
return $fields;
}