public static function TeamInvitation::baseFieldDefinitions in Apigee Edge 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
- modules/
apigee_edge_teams/ src/ Entity/ TeamInvitation.php, line 85
Class
- TeamInvitation
- Defines the team invitation entity.
Namespace
Drupal\apigee_edge_teams\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields += static::ownerBaseFieldDefinitions($entity_type);
$fields[$entity_type
->getKey('id')] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setReadOnly(TRUE);
$fields['uid']
->setDescription(t('The team invitation author.'));
$fields['label'] = BaseFieldDefinition::create('string')
->setLabel(t('Label'))
->setDescription(t('The label of the invitation.'))
->setDefaultValue('')
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Status'))
->setDescription(t('The status of the invitation.'))
->setDefaultValue(TeamInvitationInterface::STATUS_PENDING)
->setSetting('allowed_values', [
TeamInvitationInterface::STATUS_PENDING => t('Pending'),
TeamInvitationInterface::STATUS_ACCEPTED => t('Accepted'),
TeamInvitationInterface::STATUS_DECLINED => t('Declined'),
TeamInvitationInterface::STATUS_EXPIRED => t('Expired'),
])
->setRequired(TRUE);
$fields['team'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Team'))
->setDescription(t('The team for this invitation.'))
->setSetting('target_type', 'team')
->setRequired(TRUE);
$fields['team_roles'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Roles'))
->setDescription(t('The team roles for this invitation.'))
->setSetting('target_type', 'team_role')
->setRequired(TRUE)
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED);
$fields['recipient'] = BaseFieldDefinition::create('email')
->setLabel(t('Recipient'))
->setDescription(t('The email address of the invitee.'))
->setDefaultValue('')
->setRequired(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The created time for the invitation.'));
$fields['expiry'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Expiry'))
->setDescription(t('The expiry time for the invitation.'));
return $fields;
}