public static function Message::baseFieldDefinitions in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message::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 FieldableEntityInterface::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- core/
modules/ contact/ src/ Entity/ Message.php, line 137 - Contains \Drupal\contact\Entity\Message.
Class
- Message
- Defines the contact message entity.
Namespace
Drupal\contact\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['contact_form'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Form ID'))
->setDescription(t('The ID of the associated form.'))
->setSetting('target_type', 'contact_form')
->setRequired(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The message UUID.'))
->setReadOnly(TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language'))
->setDescription(t('The message language code.'))
->setDisplayOptions('form', array(
'type' => 'language_select',
'weight' => 2,
));
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t("The sender's name"))
->setDescription(t('The name of the person that is sending the contact message.'));
$fields['mail'] = BaseFieldDefinition::create('email')
->setLabel(t("The sender's email"))
->setDescription(t('The email of the person that is sending the contact message.'));
// The subject of the contact message.
$fields['subject'] = BaseFieldDefinition::create('string')
->setLabel(t('Subject'))
->setRequired(TRUE)
->setSetting('max_length', 100)
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -10,
))
->setDisplayConfigurable('form', TRUE);
// The text of the contact message.
$fields['message'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Message'))
->setRequired(TRUE)
->setDisplayOptions('form', array(
'type' => 'string_textarea',
'weight' => 0,
'settings' => array(
'rows' => 12,
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('view', array(
'type' => 'string',
'weight' => 0,
'label' => 'above',
))
->setDisplayConfigurable('view', TRUE);
$fields['copy'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Copy'))
->setDescription(t('Whether to send a copy of the message to the sender.'));
$fields['recipient'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Recipient ID'))
->setDescription(t('The ID of the recipient user for personal contact messages.'))
->setSetting('target_type', 'user');
return $fields;
}