Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / core / modules / contact / src / Entity / ContactForm.php
1 <?php
2
3 namespace Drupal\contact\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\contact\ContactFormInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Defines the contact form entity.
11  *
12  * @ConfigEntityType(
13  *   id = "contact_form",
14  *   label = @Translation("Contact form"),
15  *   label_collection = @Translation("Contact forms"),
16  *   label_singular = @Translation("contact form"),
17  *   label_plural = @Translation("contact forms"),
18  *   label_count = @PluralTranslation(
19  *     singular = "@count contact form",
20  *     plural = "@count contact forms",
21  *   ),
22  *   handlers = {
23  *     "access" = "Drupal\contact\ContactFormAccessControlHandler",
24  *     "list_builder" = "Drupal\contact\ContactFormListBuilder",
25  *     "form" = {
26  *       "add" = "Drupal\contact\ContactFormEditForm",
27  *       "edit" = "Drupal\contact\ContactFormEditForm",
28  *       "delete" = "Drupal\Core\Entity\EntityDeleteForm"
29  *     }
30  *   },
31  *   config_prefix = "form",
32  *   admin_permission = "administer contact forms",
33  *   bundle_of = "contact_message",
34  *   entity_keys = {
35  *     "id" = "id",
36  *     "label" = "label"
37  *   },
38  *   links = {
39  *     "delete-form" = "/admin/structure/contact/manage/{contact_form}/delete",
40  *     "edit-form" = "/admin/structure/contact/manage/{contact_form}",
41  *     "collection" = "/admin/structure/contact",
42  *     "canonical" = "/contact/{contact_form}",
43  *   },
44  *   config_export = {
45  *     "id",
46  *     "label",
47  *     "recipients",
48  *     "reply",
49  *     "weight",
50  *     "message",
51  *     "redirect",
52  *   }
53  * )
54  */
55 class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface {
56
57   /**
58    * The form ID.
59    *
60    * @var string
61    */
62   protected $id;
63
64   /**
65    * The human-readable label of the category.
66    *
67    * @var string
68    */
69   protected $label;
70
71   /**
72    * The message displayed to user on form submission.
73    *
74    * @var string
75    */
76   protected $message;
77
78   /**
79    * List of recipient email addresses.
80    *
81    * @var array
82    */
83   protected $recipients = [];
84
85   /**
86    * The path to redirect to on form submission.
87    *
88    * @var string
89    */
90   protected $redirect;
91
92   /**
93    * An auto-reply message.
94    *
95    * @var string
96    */
97   protected $reply = '';
98
99   /**
100    * The weight of the category.
101    *
102    * @var int
103    */
104   protected $weight = 0;
105
106   /**
107    * {@inheritdoc}
108    */
109   public function getMessage() {
110     return $this->message;
111   }
112
113   /**
114    * {@inheritdoc}
115    */
116   public function setMessage($message) {
117     $this->message = $message;
118     return $this;
119   }
120
121   /**
122    * {@inheritdoc}
123    */
124   public function getRecipients() {
125     return $this->recipients;
126   }
127
128   /**
129    * {@inheritdoc}
130    */
131   public function setRecipients($recipients) {
132     $this->recipients = $recipients;
133     return $this;
134   }
135
136   /**
137    * {@inheritdoc}
138    */
139   public function getRedirectPath() {
140     return $this->redirect;
141   }
142
143   /**
144    * {@inheritdoc}
145    */
146   public function getRedirectUrl() {
147     if ($this->redirect) {
148       $url = Url::fromUserInput($this->redirect);
149     }
150     else {
151       $url = Url::fromRoute('<front>');
152     }
153     return $url;
154   }
155
156   /**
157    * {@inheritdoc}
158    */
159   public function setRedirectPath($redirect) {
160     $this->redirect = $redirect;
161     return $this;
162   }
163
164   /**
165    * {@inheritdoc}
166    */
167   public function getReply() {
168     return $this->reply;
169   }
170
171   /**
172    * {@inheritdoc}
173    */
174   public function setReply($reply) {
175     $this->reply = $reply;
176     return $this;
177   }
178
179   /**
180    * {@inheritdoc}
181    */
182   public function getWeight() {
183     return $this->weight;
184   }
185
186   /**
187    * {@inheritdoc}
188    */
189   public function setWeight($weight) {
190     $this->weight = $weight;
191     return $this;
192   }
193
194 }