X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FEntity%2FComment.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FEntity%2FComment.php;h=8ce0c73edb9efd967d04e34160155edd6330c718;hp=a5f196646974da48c9e71ba4b35f1cc12d338630;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a diff --git a/web/core/modules/comment/src/Entity/Comment.php b/web/core/modules/comment/src/Entity/Comment.php index a5f196646..8ce0c73ed 100644 --- a/web/core/modules/comment/src/Entity/Comment.php +++ b/web/core/modules/comment/src/Entity/Comment.php @@ -81,14 +81,6 @@ class Comment extends ContentEntityBase implements CommentInterface { public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); - if (is_null($this->get('status')->value)) { - if (\Drupal::currentUser()->hasPermission('skip comment approval')) { - $this->setPublished(); - } - else { - $this->setUnpublished(); - } - } if ($this->isNew()) { // Add the comment to database. This next section builds the thread field. // @see \Drupal\comment\CommentViewBuilder::buildComponents() @@ -237,6 +229,9 @@ class Comment extends ContentEntityBase implements CommentInterface { $fields['langcode']->setDescription(t('The comment language code.')); + // Set the default value callback for the status field. + $fields['status']->setDefaultValueCallback('Drupal\comment\Entity\Comment::getDefaultStatus'); + $fields['pid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Parent ID')) ->setDescription(t('The parent comment ID if this is a reply to a comment.')) @@ -558,4 +553,16 @@ class Comment extends ContentEntityBase implements CommentInterface { return $this->bundle(); } + /** + * Default value callback for 'status' base field definition. + * + * @see ::baseFieldDefinitions() + * + * @return bool + * TRUE if the comment should be published, FALSE otherwise. + */ + public static function getDefaultStatus() { + return \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; + } + }