Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->addDefaultCommentField('node', 'page', $this->fieldName);
     $this->customComment = Comment::create(['entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => $this->fieldName]);
     $this->customComment->save();
 }
 /**
  * Publishes the specified comment.
  *
  * @param \Drupal\comment\CommentInterface $comment
  *   A comment entity.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse.
  *   Redirects to the permalink URL for this comment.
  */
 public function commentApprove(CommentInterface $comment)
 {
     $comment->setPublished(TRUE);
     $comment->save();
     drupal_set_message($this->t('Comment approved.'));
     $permalink_uri = $comment->permalink();
     $permalink_uri->setAbsolute();
     return new RedirectResponse($permalink_uri->toString());
 }
Esempio n. 3
0
 protected function updateLast($comment, $oldRevisionId, $newRevisionId, $diffFieldName, $entity, CommentInterface $lastComment)
 {
     // If there is a new revision of the host entity, update it on the comment
     if (!empty($newRevisionId)) {
         // If the last comment did not store changes, store the current revisions pair
         if (empty($lastComment->{$diffFieldName}->right_rid)) {
             $lastComment->{$diffFieldName}->setValue([['left_rid' => $oldRevisionId, 'right_rid' => $newRevisionId]]);
         } else {
             $changes = $lastComment->{$diffFieldName}->getValue();
             $changes[0]['right_rid'] = $newRevisionId;
             $lastComment->{$diffFieldName}->setValue($changes);
         }
     }
     // Overwrite the old subject only if it was a change record.
     if ($lastComment->subject->value === 'Change Record') {
         $lastComment->setSubject($comment['subject']);
     }
     // Set all fields for which data has been passed
     // and there is no saved value
     foreach ($comment as $name => $value) {
         if (!isset($lastComment->{$name}->value)) {
             if (is_array($value)) {
                 $lastComment->{$name}->setValue($value);
             } else {
                 $lastComment->{$name}->value = $value;
             }
         }
     }
     $lastComment->setChangedTime(REQUEST_TIME);
     $lastComment->save();
 }