public static function Group::baseFieldDefinitions in Group 8
Same name and namespace in other branches
- 2.0.x src/Entity/Group.php \Drupal\group\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 EditorialContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- src/
Entity/ Group.php, line 229
Class
- Group
- Defines the Group entity.
Namespace
Drupal\group\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields += static::ownerBaseFieldDefinitions($entity_type);
// @todo Remove the usage of StatusItem in
// https://www.drupal.org/project/drupal/issues/2936864.
$fields['status']
->getItemDefinition()
->setClass(StatusItem::class);
$fields['status']
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
],
'weight' => 120,
])
->setDisplayConfigurable('form', TRUE);
$fields['label'] = BaseFieldDefinition::create('string')
->setLabel(t('Title'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE)
->setRevisionable(TRUE);
$fields['uid']
->setLabel(t('Group creator'))
->setDescription(t('The username of the group creator.'))
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE)
->setRevisionable(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created on'))
->setDescription(t('The time that the group was created.'))
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'region' => 'hidden',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setRevisionable(TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed on'))
->setDescription(t('The time that the group was last edited.'))
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'region' => 'hidden',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setRevisionable(TRUE);
if (\Drupal::moduleHandler()
->moduleExists('path')) {
$fields['path'] = BaseFieldDefinition::create('path')
->setLabel(t('URL alias'))
->setTranslatable(TRUE)
->setDisplayOptions('form', [
'type' => 'path',
'weight' => 30,
])
->setDisplayConfigurable('form', TRUE)
->setComputed(TRUE);
}
return $fields;
}