Comment.php 4.74 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Drupal\comment\Plugin\Core\Entity\Comment.
6
7
 */

8
namespace Drupal\comment\Plugin\Core\Entity;
9

10
use Drupal\Core\Entity\ContentEntityInterface;
11
use Drupal\Core\Entity\EntityNG;
12
use Drupal\Core\Entity\Annotation\EntityType;
13
use Drupal\Core\Annotation\Translation;
14
15
16

/**
 * Defines the comment entity class.
17
 *
18
 * @EntityType(
19
20
 *   id = "comment",
 *   label = @Translation("Comment"),
21
 *   bundle_label = @Translation("Content type"),
22
 *   module = "comment",
23
24
25
26
27
28
29
30
 *   controllers = {
 *     "storage" = "Drupal\comment\CommentStorageController",
 *     "access" = "Drupal\comment\CommentAccessController",
 *     "render" = "Drupal\comment\CommentRenderController",
 *     "form" = {
 *       "default" = "Drupal\comment\CommentFormController"
 *     },
 *     "translation" = "Drupal\comment\CommentTranslationController"
31
32
33
34
 *   },
 *   base_table = "comment",
 *   uri_callback = "comment_uri",
 *   fieldable = TRUE,
35
 *   translatable = TRUE,
36
37
38
39
40
41
42
43
 *   static_cache = FALSE,
 *   entity_keys = {
 *     "id" = "cid",
 *     "bundle" = "node_type",
 *     "label" = "subject",
 *     "uuid" = "uuid"
 *   }
 * )
44
 */
45
class Comment extends EntityNG implements ContentEntityInterface {
46
47
48
49

  /**
   * The comment ID.
   *
50
51
52
   * @todo Rename to 'id'.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
53
54
55
   */
  public $cid;

56
57
58
  /**
   * The comment UUID.
   *
59
   * @var \Drupal\Core\Entity\Field\FieldInterface
60
61
62
   */
  public $uuid;

63
64
65
  /**
   * The parent comment ID if this is a reply to a comment.
   *
66
67
68
   * @todo: Rename to 'parent_id'.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
69
70
71
   */
  public $pid;

72
73
  /**
   * The ID of the node to which the comment is attached.
74
75
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
76
77
78
   */
  public $nid;

79
80
81
  /**
   * The comment language code.
   *
82
   * @var \Drupal\Core\Entity\Field\FieldInterface
83
   */
84
  public $langcode;
85
86
87
88

  /**
   * The comment title.
   *
89
   * @var \Drupal\Core\Entity\Field\FieldInterface
90
91
92
93
94
95
96
   */
  public $subject;


  /**
   * The comment author ID.
   *
97
   * @var \Drupal\Core\Entity\Field\FieldInterface
98
   */
99
  public $uid;
100
101
102
103
104
105

  /**
   * The comment author's name.
   *
   * For anonymous authors, this is the value as typed in the comment form.
   *
106
   * @var \Drupal\Core\Entity\Field\FieldInterface
107
   */
108
  public $name;
109
110
111
112
113
114

  /**
   * The comment author's e-mail address.
   *
   * For anonymous authors, this is the value as typed in the comment form.
   *
115
   * @var \Drupal\Core\Entity\Field\FieldInterface
116
117
118
119
120
121
122
123
   */
  public $mail;

  /**
   * The comment author's home page address.
   *
   * For anonymous authors, this is the value as typed in the comment form.
   *
124
   * @var \Drupal\Core\Entity\Field\FieldInterface
125
126
127
128
   */
  public $homepage;

  /**
129
130
131
   * The comment author's hostname.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
132
   */
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  public $hostname;

  /**
   * The time that the comment was created.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $created;

  /**
   * The time that the comment was last edited.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $changed;

  /**
   * A boolean field indicating whether the comment is published.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $status;

  /**
   * The alphadecimal representation of the comment's place in a thread.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $thread;

  /**
   * The comment node type.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $node_type;

  /**
   * The comment 'new' marker for the current user.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $new;

  /**
   * The plain data values of the contained properties.
   *
   * Define default values.
   *
   * @var array
   */
  protected $values = array(
    'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))),
    'name' => array(LANGUAGE_DEFAULT => array(0 => array('value' => ''))),
187
    'uid' => array(LANGUAGE_DEFAULT => array(0 => array('target_id' => 0))),
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
  );

  /**
   * Initialize the object. Invoked upon construction and wake up.
   */
  protected function init() {
    parent::init();
    // We unset all defined properties, so magic getters apply.
    unset($this->cid);
    unset($this->uuid);
    unset($this->pid);
    unset($this->nid);
    unset($this->subject);
    unset($this->uid);
    unset($this->name);
    unset($this->mail);
    unset($this->homepage);
    unset($this->hostname);
    unset($this->created);
    unset($this->changed);
    unset($this->status);
    unset($this->thread);
    unset($this->node_type);
    unset($this->new);
212
213
214
  }

  /**
215
   * Implements Drupal\Core\Entity\EntityInterface::id().
216
   */
217
218
  public function id() {
    return $this->get('cid')->value;
219
220
  }
}