Mercurial > hg > isophonics-drupal-site
comparison core/modules/contact/src/Entity/Message.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\contact\Entity; | |
4 | |
5 use Drupal\Core\Entity\ContentEntityBase; | |
6 use Drupal\contact\MessageInterface; | |
7 use Drupal\Core\Entity\EntityTypeInterface; | |
8 use Drupal\Core\Field\BaseFieldDefinition; | |
9 | |
10 /** | |
11 * Defines the contact message entity. | |
12 * | |
13 * @ContentEntityType( | |
14 * id = "contact_message", | |
15 * label = @Translation("Contact message"), | |
16 * bundle_label = @Translation("Contact form"), | |
17 * handlers = { | |
18 * "access" = "Drupal\contact\ContactMessageAccessControlHandler", | |
19 * "storage" = "Drupal\Core\Entity\ContentEntityNullStorage", | |
20 * "view_builder" = "Drupal\contact\MessageViewBuilder", | |
21 * "form" = { | |
22 * "default" = "Drupal\contact\MessageForm" | |
23 * } | |
24 * }, | |
25 * admin_permission = "administer contact forms", | |
26 * entity_keys = { | |
27 * "bundle" = "contact_form", | |
28 * "uuid" = "uuid", | |
29 * "langcode" = "langcode" | |
30 * }, | |
31 * bundle_entity_type = "contact_form", | |
32 * field_ui_base_route = "entity.contact_form.edit_form", | |
33 * ) | |
34 */ | |
35 class Message extends ContentEntityBase implements MessageInterface { | |
36 | |
37 /** | |
38 * {@inheritdoc} | |
39 */ | |
40 public function isPersonal() { | |
41 return $this->bundle() == 'personal'; | |
42 } | |
43 | |
44 /** | |
45 * {@inheritdoc} | |
46 */ | |
47 public function getContactForm() { | |
48 return $this->get('contact_form')->entity; | |
49 } | |
50 | |
51 /** | |
52 * {@inheritdoc} | |
53 */ | |
54 public function getSenderName() { | |
55 return $this->get('name')->value; | |
56 } | |
57 | |
58 /** | |
59 * {@inheritdoc} | |
60 */ | |
61 public function setSenderName($sender_name) { | |
62 $this->set('name', $sender_name); | |
63 } | |
64 | |
65 /** | |
66 * {@inheritdoc} | |
67 */ | |
68 public function getSenderMail() { | |
69 return $this->get('mail')->value; | |
70 } | |
71 | |
72 /** | |
73 * {@inheritdoc} | |
74 */ | |
75 public function setSenderMail($sender_mail) { | |
76 $this->set('mail', $sender_mail); | |
77 } | |
78 | |
79 /** | |
80 * {@inheritdoc} | |
81 */ | |
82 public function getSubject() { | |
83 return $this->get('subject')->value; | |
84 } | |
85 | |
86 /** | |
87 * {@inheritdoc} | |
88 */ | |
89 public function setSubject($subject) { | |
90 $this->set('subject', $subject); | |
91 } | |
92 | |
93 /** | |
94 * {@inheritdoc} | |
95 */ | |
96 public function getMessage() { | |
97 return $this->get('message')->value; | |
98 } | |
99 | |
100 /** | |
101 * {@inheritdoc} | |
102 */ | |
103 public function setMessage($message) { | |
104 $this->set('message', $message); | |
105 } | |
106 | |
107 /** | |
108 * {@inheritdoc} | |
109 */ | |
110 public function copySender() { | |
111 return (bool) $this->get('copy')->value; | |
112 } | |
113 | |
114 /** | |
115 * {@inheritdoc} | |
116 */ | |
117 public function setCopySender($inform) { | |
118 $this->set('copy', (bool) $inform); | |
119 } | |
120 | |
121 /** | |
122 * {@inheritdoc} | |
123 */ | |
124 public function getPersonalRecipient() { | |
125 if ($this->isPersonal()) { | |
126 return $this->get('recipient')->entity; | |
127 } | |
128 } | |
129 | |
130 /** | |
131 * {@inheritdoc} | |
132 */ | |
133 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { | |
134 /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ | |
135 $fields = parent::baseFieldDefinitions($entity_type); | |
136 | |
137 $fields['contact_form']->setLabel(t('Form ID')) | |
138 ->setDescription(t('The ID of the associated form.')); | |
139 | |
140 $fields['uuid']->setDescription(t('The message UUID.')); | |
141 | |
142 $fields['langcode']->setDescription(t('The message language code.')); | |
143 | |
144 $fields['name'] = BaseFieldDefinition::create('string') | |
145 ->setLabel(t("The sender's name")) | |
146 ->setDescription(t('The name of the person that is sending the contact message.')); | |
147 | |
148 $fields['mail'] = BaseFieldDefinition::create('email') | |
149 ->setLabel(t("The sender's email")) | |
150 ->setDescription(t('The email of the person that is sending the contact message.')); | |
151 | |
152 // The subject of the contact message. | |
153 $fields['subject'] = BaseFieldDefinition::create('string') | |
154 ->setLabel(t('Subject')) | |
155 ->setRequired(TRUE) | |
156 ->setSetting('max_length', 100) | |
157 ->setDisplayOptions('form', [ | |
158 'type' => 'string_textfield', | |
159 'weight' => -10, | |
160 ]) | |
161 ->setDisplayConfigurable('form', TRUE); | |
162 | |
163 // The text of the contact message. | |
164 $fields['message'] = BaseFieldDefinition::create('string_long') | |
165 ->setLabel(t('Message')) | |
166 ->setRequired(TRUE) | |
167 ->setDisplayOptions('form', [ | |
168 'type' => 'string_textarea', | |
169 'weight' => 0, | |
170 'settings' => [ | |
171 'rows' => 12, | |
172 ], | |
173 ]) | |
174 ->setDisplayConfigurable('form', TRUE) | |
175 ->setDisplayOptions('view', [ | |
176 'type' => 'string', | |
177 'weight' => 0, | |
178 'label' => 'above', | |
179 ]) | |
180 ->setDisplayConfigurable('view', TRUE); | |
181 | |
182 $fields['copy'] = BaseFieldDefinition::create('boolean') | |
183 ->setLabel(t('Copy')) | |
184 ->setDescription(t('Whether to send a copy of the message to the sender.')); | |
185 | |
186 $fields['recipient'] = BaseFieldDefinition::create('entity_reference') | |
187 ->setLabel(t('Recipient ID')) | |
188 ->setDescription(t('The ID of the recipient user for personal contact messages.')) | |
189 ->setSetting('target_type', 'user'); | |
190 | |
191 return $fields; | |
192 } | |
193 | |
194 } |