public static function Group::baseFieldDefinitions in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Entity/Group.php \Drupal\rng\Entity\Group::baseFieldDefinitions()
- 3.x src/Entity/Group.php \Drupal\rng\Entity\Group::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/ Group.php, line 117
Class
- Group
- Defines the application group entity class.
Namespace
Drupal\rng\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Group ID'))
->setDescription(t('The group ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The group UUID.'))
->setReadOnly(TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The group language code.'));
$fields['event'] = BaseFieldDefinition::create('dynamic_entity_reference')
->setLabel(t('Event'))
->setDescription(t('The groups event, or leave empty for global.'))
->setReadOnly(TRUE);
$fields['source'] = BaseFieldDefinition::create('string')
->setLabel(t('Source module'))
->setDescription(t('The module which created this group. Or NULL if it is user created.'))
->setReadOnly(TRUE);
$fields['label'] = BaseFieldDefinition::create('string')
->setLabel(t('Label'))
->setDescription(t('Name of the group.'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setDefaultValue('')
->setSetting('max_length', 255)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'string',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => 0,
))
->setDisplayConfigurable('form', TRUE);
$fields['description'] = BaseFieldDefinition::create('text_long')
->setLabel(t('Description'))
->setDescription(t('A description of the group.'))
->setTranslatable(TRUE)
->setDisplayOptions('form', array(
'type' => 'text_textfield',
'weight' => 50,
))
->setDisplayConfigurable('form', TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created on'))
->setDescription(t('The time that the group was created.'))
->setTranslatable(TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The last time the group was edited.'))
->setTranslatable(TRUE);
$fields['groups_dependent'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Dependent groups'))
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDescription(t('Groups required for this group to be added to a registration.'))
->setSetting('target_type', 'registration_group')
->setSetting('handler', 'siblings')
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => 70,
])
->setDisplayConfigurable('form', TRUE);
$fields['groups_conflicting'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Conflicting groups'))
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDescription(t('Groups cannot exist on a registration for this group to be added.'))
->setSetting('target_type', 'registration_group')
->setSetting('handler', 'siblings')
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => 75,
])
->setDisplayConfigurable('form', TRUE);
return $fields;
}