class Message
Same name in this branch
- main composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
Same name and namespace in other branches
- 10 composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
- 11.x composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
- 11.x core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
- 10 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
- 9 composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
- 9 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
- 8.9.x composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
- 8.9.x core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
Defines the contact message entity.
Attributes
#[ContentEntityType(id: 'contact_message', label: new TranslatableMarkup('Contact message'), label_collection: new TranslatableMarkup('Contact messages'), label_singular: new TranslatableMarkup('contact message'), label_plural: new TranslatableMarkup('contact messages'), entity_keys: [
'bundle' => 'contact_form',
'uuid' => 'uuid',
'langcode' => 'langcode',
], handlers: [
'access' => ContactMessageAccessControlHandler::class,
'storage' => ContentEntityNullStorage::class,
'view_builder' => MessageViewBuilder::class,
'form' => [
'default' => MessageForm::class,
],
], admin_permission: 'administer contact forms', bundle_entity_type: 'contact_form', bundle_label: new TranslatableMarkup('Contact form'), label_count: [
'singular' => '@count contact message',
'plural' => '@count contact messages',
], field_ui_base_route: 'entity.contact_form.edit_form')]
Hierarchy
- class \Drupal\contact\Entity\Message implements \Drupal\contact\MessageInterface extends \Drupal\Core\Entity\ContentEntityBase
Expanded class hierarchy of Message
3 files declare their use of Message
- ContactStorageTest.php in core/
modules/ contact/ tests/ src/ Functional/ ContactStorageTest.php - MessageResourceTestBase.php in core/
modules/ contact/ tests/ src/ Functional/ Rest/ MessageResourceTestBase.php - MessageTest.php in core/
modules/ contact/ tests/ src/ Functional/ Jsonapi/ MessageTest.php
44 string references to 'Message'
- AjaxTestController::renderError in core/
modules/ system/ tests/ modules/ ajax_test/ src/ Controller/ AjaxTestController.php - Returns an AjaxResponse with alert command.
- ConfigEntityImportTest::doActionUpdate in core/
modules/ system/ tests/ src/ Kernel/ Entity/ ConfigEntityImportTest.php - Tests updating an action during import.
- ConfigEntityValidationTestBase::testInvalidMachineNameCharacters in core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigEntityValidationTestBase.php - Tests that the entity's ID is tested for invalid characters.
- ConfigExportUITest::testExport in core/
modules/ config/ tests/ src/ Functional/ ConfigExportUITest.php - Tests export of configuration.
- ConnectionFailureTest::testConnectionFailureLogging in core/
modules/ dblog/ tests/ src/ Kernel/ ConnectionFailureTest.php - Tests logging of connection failures.
File
-
core/
modules/ contact/ src/ Entity/ Message.php, line 19
Namespace
Drupal\contact\EntityView source
class Message extends ContentEntityBase implements MessageInterface {
/**
* {@inheritdoc}
*/
public function isPersonal() {
return $this->bundle() == 'personal';
}
/**
* {@inheritdoc}
*/
public function getContactForm() {
return $this->get('contact_form')->entity;
}
/**
* {@inheritdoc}
*/
public function getSenderName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setSenderName($sender_name) {
$this->set('name', $sender_name);
}
/**
* {@inheritdoc}
*/
public function getSenderMail() {
return $this->get('mail')->value;
}
/**
* {@inheritdoc}
*/
public function setSenderMail($sender_mail) {
$this->set('mail', $sender_mail);
}
/**
* {@inheritdoc}
*/
public function getSubject() {
return $this->get('subject')->value;
}
/**
* {@inheritdoc}
*/
public function setSubject($subject) {
$this->set('subject', $subject);
}
/**
* {@inheritdoc}
*/
public function getMessage() {
return $this->get('message')->value;
}
/**
* {@inheritdoc}
*/
public function setMessage($message) {
$this->set('message', $message);
}
/**
* {@inheritdoc}
*/
public function copySender() {
return (bool) $this->get('copy')->value;
}
/**
* {@inheritdoc}
*/
public function setCopySender($inform) {
$this->set('copy', (bool) $inform);
}
/**
* {@inheritdoc}
*/
public function getPersonalRecipient() {
if ($this->isPersonal()) {
return $this->get('recipient')->entity;
}
}
/**
* {@inheritdoc}
*/
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.