class Comment

Defines the comment entity class.

Plugin annotation


@EntityType(
  id = "comment",
  label = @Translation("Comment"),
  bundle_label = @Translation("Content type"),
  module = "comment",
  controllers = {
    "storage" = "Drupal\comment\CommentStorageController",
    "access" = "Drupal\comment\CommentAccessController",
    "render" = "Drupal\comment\CommentRenderController",
    "form" = {
      "default" = "Drupal\comment\CommentFormController"
    },
    "translation" = "Drupal\comment\CommentTranslationController"
  },
  base_table = "comment",
  uri_callback = "comment_uri",
  fieldable = TRUE,
  translatable = TRUE,
  route_base_path = "admin/structure/types/manage/{bundle}/comment",
  bundle_prefix = "comment_node_",
  entity_keys = {
    "id" = "cid",
    "bundle" = "node_type",
    "label" = "subject",
    "uuid" = "uuid"
  },
  links = {
    "canonical" = "/comment/{comment}",
    "edit-form" = "/comment/{comment}/edit"
  }
)

Hierarchy

Expanded class hierarchy of Comment

5 files declare their use of Comment
comment.admin.inc in drupal/core/modules/comment/comment.admin.inc
Admin page callbacks for the Comment module.
comment.module in drupal/core/modules/comment/comment.module
Enables users to comment on published content.
comment.pages.inc in drupal/core/modules/comment/comment.pages.inc
User page callbacks for the Comment module.
CommentTestBase.php in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
Contains Drupal\comment\Tests\CommentTestBase.
user.module in drupal/core/modules/user/user.module
Enables the user registration and login system.
27 string references to 'Comment'
comment.info.yml in drupal/core/modules/comment/comment.info.yml
drupal/core/modules/comment/comment.info.yml
CommentActionsTest::getInfo in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php
CommentAnonymousTest::getInfo in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php
CommentApprovalTest::getInfo in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentApprovalTest.php
CommentBlockTest::getInfo in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php

... See full list

File

drupal/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php, line 51
Definition of Drupal\comment\Plugin\Core\Entity\Comment.

Namespace

Drupal\comment\Plugin\Core\Entity
View source
class Comment extends EntityNG implements CommentInterface {

  /**
   * The comment ID.
   *
   * @todo Rename to 'id'.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $cid;

  /**
   * The comment UUID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $uuid;

  /**
   * The parent comment ID if this is a reply to a comment.
   *
   * @todo: Rename to 'parent_id'.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $pid;

  /**
   * The ID of the node to which the comment is attached.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $nid;

  /**
   * The comment language code.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $langcode;

  /**
   * The comment title.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $subject;

  /**
   * The comment author ID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $uid;

  /**
   * The comment author's name.
   *
   * For anonymous authors, this is the value as typed in the comment form.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $name;

  /**
   * The comment author's e-mail address.
   *
   * For anonymous authors, this is the value as typed in the comment form.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $mail;

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

  /**
   * The comment author's hostname.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  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::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => Language::LANGCODE_NOT_SPECIFIED,
        ),
      ),
    ),
    'name' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => '',
        ),
      ),
    ),
    'uid' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'target_id' => 0,
        ),
      ),
    ),
  );

  /**
   * 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);
  }

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

  /**
   * {@inheritdoc}
   */
  public function permalink() {
    $url['path'] = 'node/' . $this->nid->value;
    $url['options'] = array(
      'fragment' => 'comment-' . $this
        ->id(),
    );
    return $url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Comment::$changed public property The time that the comment was last edited.
Comment::$cid public property The comment ID.
Comment::$created public property The time that the comment was created.
Comment::$homepage public property The comment author's home page address.
Comment::$hostname public property The comment author's hostname.
Comment::$langcode public property The comment language code. Overrides Entity::$langcode
Comment::$mail public property The comment author's e-mail address.
Comment::$name public property The comment author's name.
Comment::$new public property The comment 'new' marker for the current user.
Comment::$nid public property The ID of the node to which the comment is attached.
Comment::$node_type public property The comment node type.
Comment::$pid public property The parent comment ID if this is a reply to a comment.
Comment::$status public property A boolean field indicating whether the comment is published.
Comment::$subject public property The comment title.
Comment::$thread public property The alphadecimal representation of the comment's place in a thread.
Comment::$uid public property The comment author ID.
Comment::$uuid public property The comment UUID.
Comment::$values protected property The plain data values of the contained properties. Overrides EntityNG::$values
Comment::id public function Implements Drupal\Core\Entity\EntityInterface::id(). Overrides EntityNG::id
Comment::init protected function Initialize the object. Invoked upon construction and wake up. Overrides EntityNG::init
Comment::permalink public function Returns the permalink URL for this comment. Overrides CommentInterface::permalink
Entity::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
Entity::$entityType protected property The entity type.
Entity::$isDefaultRevision protected property Indicates whether this is the default revision. 1
Entity::$newRevision protected property Boolean indicating whether a new revision should be created on save.
Entity::access public function Implements \Drupal\Core\TypedData\AccessibleInterface::access(). Overrides AccessibleInterface::access
Entity::delete public function Implements \Drupal\Core\Entity\EntityInterface::delete(). Overrides EntityInterface::delete 3
Entity::enforceIsNew public function Implements \Drupal\Core\Entity\EntityInterface::enforceIsNew(). Overrides EntityInterface::enforceIsNew
Entity::entityInfo public function Implements \Drupal\Core\Entity\EntityInterface::entityInfo(). Overrides EntityInterface::entityInfo
Entity::entityType public function Implements \Drupal\Core\Entity\EntityInterface::entityType(). Overrides EntityInterface::entityType
Entity::getConstraints public function Implements \Drupal\Core\TypedData\TypedDataInterface::getConstraints(). Overrides TypedDataInterface::getConstraints
Entity::getDefinition public function Implements \Drupal\Core\TypedData\TypedDataInterface::getDefinition(). Overrides TypedDataInterface::getDefinition
Entity::getExportProperties public function Implements \Drupal\Core\Entity\EntityInterface::getExportProperties(). Overrides EntityInterface::getExportProperties 1
Entity::getName public function Implements \Drupal\Core\TypedData\TypedDataInterface::getName(). Overrides TypedDataInterface::getName
Entity::getNGEntity public function Implements \Drupal\Core\Entity\EntityInterface::getNGEntity(). Overrides EntityInterface::getNGEntity
Entity::getParent public function Implements \Drupal\Core\TypedData\TypedDataInterface::getParent(). Overrides TypedDataInterface::getParent
Entity::getPropertyPath public function Implements \Drupal\Core\TypedData\TypedDataInterface::getPropertyPath(). Overrides TypedDataInterface::getPropertyPath
Entity::getRevisionId public function Implements \Drupal\Core\Entity\EntityInterface::getRevisionId(). Overrides EntityInterface::getRevisionId 4
Entity::getRoot public function Implements \Drupal\Core\TypedData\TypedDataInterface::getRoot(). Overrides TypedDataInterface::getRoot
Entity::getString public function Implements \Drupal\Core\TypedData\TypedDataInterface::getString(). Overrides TypedDataInterface::getString
Entity::getValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). Overrides TypedDataInterface::getValue
Entity::isDefaultRevision public function Implements \Drupal\Core\Entity\EntityInterface::isDefaultRevision(). Overrides EntityInterface::isDefaultRevision 1
Entity::isNew public function Implements \Drupal\Core\Entity\EntityInterface::isNew(). Overrides EntityInterface::isNew 1
Entity::isNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::isNewRevision(). Overrides EntityInterface::isNewRevision
Entity::isTranslatable public function Implements \Drupal\Core\Entity\EntityInterface::isTranslatable(). Overrides EntityInterface::isTranslatable
Entity::onChange public function Implements \Drupal\Core\TypedData\ComplexDataInterface::onChange(). Overrides ComplexDataInterface::onChange
Entity::save public function Implements \Drupal\Core\Entity\EntityInterface::save(). Overrides EntityInterface::save 6
Entity::setContext public function Implements \Drupal\Core\TypedData\TypedDataInterface::setContext(). Overrides TypedDataInterface::setContext
Entity::setNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::setNewRevision(). Overrides EntityInterface::setNewRevision
Entity::setValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). Overrides TypedDataInterface::setValue
Entity::uriRelationships public function Returns a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityNG::$bcEntity protected property An instance of the backward compatibility decorator.
EntityNG::$bundle protected property Local cache holding the value of the bundle field.
EntityNG::$fieldDefinitions protected property Local cache for field definitions.
EntityNG::$fields protected property The array of fields, each being an instance of FieldInterface.
EntityNG::$uriPlaceholderReplacements protected property Local cache for URI placeholder substitution values.
EntityNG::bundle public function Implements \Drupal\Core\Entity\EntityInterface::bundle(). Overrides Entity::bundle
EntityNG::createDuplicate public function Overrides Entity::createDuplicate(). Overrides Entity::createDuplicate 1
EntityNG::get public function Implements \Drupal\Core\TypedData\ComplexDataInterface::get(). Overrides Entity::get
EntityNG::getBCEntity public function Overrides Entity::getBCEntity(). Overrides Entity::getBCEntity 2
EntityNG::getIterator public function Implements \IteratorAggregate::getIterator(). Overrides Entity::getIterator
EntityNG::getProperties public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getProperties(). Overrides Entity::getProperties
EntityNG::getPropertyDefinition public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition(). Overrides Entity::getPropertyDefinition
EntityNG::getPropertyDefinitions public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). Overrides Entity::getPropertyDefinitions
EntityNG::getPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues(). Overrides Entity::getPropertyValues
EntityNG::getTranslatedField protected function Gets a translated field.
EntityNG::getTranslation public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). Overrides Entity::getTranslation
EntityNG::getTranslationLanguages public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). Overrides Entity::getTranslationLanguages
EntityNG::getType public function Gets the typed data type of the entity. Overrides Entity::getType
EntityNG::isEmpty public function Implements \Drupal\Core\TypedData\ComplexDataInterface::isEmpty(). Overrides Entity::isEmpty
EntityNG::label public function Overrides Entity::label() to access the label field with the new API. Overrides Entity::label 3
EntityNG::language public function Implements \Drupal\Core\TypedData\TranslatableInterface::language(). Overrides Entity::language
EntityNG::set public function Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). Overrides Entity::set
EntityNG::setPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues(). Overrides Entity::setPropertyValues
EntityNG::translations public function Overrides Entity::translations(). Overrides Entity::translations
EntityNG::updateOriginalValues public function Updates the original values with the interim changes.
EntityNG::uri public function Implements \Drupal\Core\Entity\EntityInterface::uri(). Overrides Entity::uri 1
EntityNG::uriPlaceholderReplacements protected function Returns an array of placeholders for this entity.
EntityNG::uuid public function Overrides Entity::uuid(). Overrides Entity::uuid
EntityNG::validate public function Implements \Drupal\Core\TypedData\TypedDataInterface::validate(). Overrides Entity::validate
EntityNG::__clone public function Magic method: Implements a deep clone.
EntityNG::__construct public function Overrides Entity::__construct(). Overrides Entity::__construct
EntityNG::__get public function Implements the magic method for setting object properties.
EntityNG::__isset public function Implements the magic method for isset().
EntityNG::__set public function Implements the magic method for setting object properties.
EntityNG::__unset public function Implements the magic method for unset.
EntityNG::__wakeup public function Magic __wakeup() implementation.