function Message::baseFieldDefinitions

Same name in other branches
  1. 9 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message::baseFieldDefinitions()
  2. 10 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message::baseFieldDefinitions()
  3. 11.x core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message::baseFieldDefinitions()

Overrides ContentEntityBase::baseFieldDefinitions

File

core/modules/contact/src/Entity/Message.php, line 140

Class

Message
Defines the contact message entity.

Namespace

Drupal\contact\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields['contact_form']->setLabel(t('Form ID'))
        ->setDescription(t('The ID of the associated form.'));
    $fields['uuid']->setDescription(t('The message UUID.'));
    $fields['langcode']->setDescription(t('The message language code.'));
    $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', [
        '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', [
        'type' => 'string_textarea',
        'weight' => 0,
        'settings' => [
            'rows' => 12,
        ],
    ])
        ->setDisplayConfigurable('form', TRUE)
        ->setDisplayOptions('view', [
        '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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.