getParentComment example

->fetchField();
  }

  /** * {@inheritdoc} */
  public function getMaxThreadPerThread(CommentInterface $comment) {
    $query = $this->database->select($this->getDataTable(), 'c')
      ->condition('entity_id', $comment->getCommentedEntityId())
      ->condition('field_name', $comment->getFieldName())
      ->condition('entity_type', $comment->getCommentedEntityTypeId())
      ->condition('thread', $comment->getParentComment()->getThread() . '.%', 'LIKE')
      ->condition('default_langcode', 1);
    $query->addExpression('MAX([thread])', 'thread');
    return $query->execute()
      ->fetchField();
  }

  /** * {@inheritdoc} */
  public function getDisplayOrdinal(CommentInterface $comment$comment_mode$divisor = 1) {
    // Count how many comments (c1) are before $comment (c2) in display order.
$tests['[comment:author]'] = Html::escape($comment->getAuthorName());
    $tests['[comment:mail]'] = $this->adminUser->getEmail();
    $tests['[comment:homepage]'] = UrlHelper::filterBadProtocol($comment->getHomepage());
    $tests['[comment:title]'] = Html::escape($comment->getSubject());
    $tests['[comment:body]'] = $comment->comment_body->processed;
    $tests['[comment:langcode]'] = $comment->language()->getId();
    $tests['[comment:url]'] = $comment->toUrl('canonical', $url_options + ['fragment' => 'comment-' . $comment->id()])->toString();
    $tests['[comment:edit-url]'] = $comment->toUrl('edit-form', $url_options)->toString();
    $tests['[comment:created]'] = \Drupal::service('date.formatter')->format($comment->getCreatedTime(), 'medium', ['langcode' => $language_interface->getId()]);
    $tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getCreatedTime()['langcode' => $language_interface->getId()]);
    $tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getChangedTimeAcrossTranslations()['langcode' => $language_interface->getId()]);
    $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL;
    $tests['[comment:parent:title]'] = $parent_comment->getSubject();
    $tests['[comment:entity]'] = Html::escape($node->getTitle());
    // Test node specific tokens.     $tests['[comment:entity:nid]'] = $comment->getCommentedEntityId();
    $tests['[comment:entity:title]'] = Html::escape($node->getTitle());
    $tests['[comment:author:uid]'] = $comment->getOwnerId();
    $tests['[comment:author:name]'] = Html::escape($this->adminUser->getDisplayName());

    $base_bubbleable_metadata = BubbleableMetadata::createFromObject($comment);
    $metadata_tests = [];
    $metadata_tests['[comment:cid]'] = $base_bubbleable_metadata;
    
          $max = rtrim((string) $max, '/');
          // We need to get the value at the correct depth.           $parts = explode('.', $max);
          $n = Number::alphadecimalToInt($parts[0]);
          $prefix = '';
        }
        else {
          // This is a comment with a parent comment, so increase the part of           // the thread value at the proper depth.
          // Get the parent comment:           $parent = $this->getParentComment();
          // Strip the "/" from the end of the parent thread.           $parent->setThread((string) rtrim((string) $parent->getThread(), '/'));
          $prefix = $parent->getThread() . '.';
          // Get the max value in *this* thread.           $max = $storage->getMaxThreadPerThread($this);

          if ($max == '') {
            // First child of this parent. As the other two cases do an             // increment of the thread number before creating the thread             // string set this to -1 so it requires an increment too.             $n = -1;
          }
// Deliberately use the wrong URL to test     // \Drupal\comment\Controller\CommentController::redirectNode().     $this->drupalGet('comment/' . $this->node->id() . '/reply');
    // Verify we were correctly redirected.     $this->assertSession()->addressEquals(Url::fromRoute('comment.reply', ['entity_type' => 'node', 'entity' => $this->node->id(), 'field_name' => 'comment']));
    $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id());
    $this->assertSession()->pageTextContains($subject_text);
    $this->assertSession()->pageTextContains($comment_text);
    $reply = $this->postComment(NULL, $this->randomMachineName(), '', TRUE);
    $reply_loaded = Comment::load($reply->id());
    $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
    $this->assertEquals($comment->id()$reply_loaded->getParentComment()->id(), 'Pid of a reply to a comment is set correctly.');
    // Check the thread of reply grows correctly.     $this->assertEquals(rtrim($comment->getThread(), '/') . '.00/', $reply_loaded->getThread());

    // Second reply to comment #2 creating comment #4.     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id());
    $this->assertSession()->pageTextContains($comment->getSubject());
    $this->assertSession()->pageTextContains($comment->comment_body->value);
    $reply = $this->postComment(NULL, $this->randomMachineName()$this->randomMachineName(), TRUE);
    $reply_loaded = Comment::load($reply->id());
    $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.');
    // Check the thread of second reply grows correctly.
Home | Imprint | This part of the site doesn't use cookies.