public static function PrivateMessageThread::baseFieldDefinitions in Private Message 8.2
Same name and namespace in other branches
- 8 src/Entity/PrivateMessageThread.php \Drupal\private_message\Entity\PrivateMessageThread::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()
1 call to PrivateMessageThread::baseFieldDefinitions()
- PrivateMessageForm::validateMembers in src/
Form/ PrivateMessageForm.php - Validate members that have been added to a private message thread.
File
- src/
Entity/ PrivateMessageThread.php, line 284
Class
- PrivateMessageThread
- Defines the Private Message Thread entity.
Namespace
Drupal\private_message\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entityType) {
$fields = parent::baseFieldDefinitions($entityType);
$fields['id']
->setLabel(t('Private message thread ID'))
->setDescription(t('The private message thread ID.'));
$fields['uuid']
->setDescription(t('The custom private message thread UUID.'));
$fields['updated'] = BaseFieldDefinition::create('changed')
->setLabel(t('Updated'))
->setDescription(t('The most recent time at which the thread was updated'));
// Member(s) of the private message thread.
// Entity reference field, holds the reference to user objects.
$fields['members'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Member(s)'))
->setDescription(t('The member(s) of the private message thread'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->addConstraint('private_message_thread_member')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'entity_reference_label',
'weight' => -3,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'settings' => [
'match_operator' => 'CONTAINS',
'match_limit' => 10,
'max_members' => 0,
'size' => 60,
'autocomplete_type' => 'tags',
'placeholder' => '',
],
'weight' => -3,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
// Private messages in this thread.
// Entity reference field, holds the reference to user objects.
$fields['private_messages'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Messages'))
->setDescription(t('The private messages that belong to this thread'))
->setSetting('target_type', 'private_message')
->setSetting('handler', 'default')
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'entity_reference_entity_view',
])
->setDisplayConfigurable('view', TRUE);
return $fields;
}