permalink example


  public function commentApprove(CommentInterface $comment) {
    $comment->setPublished();
    $comment->save();

    $this->messenger()->addStatus($this->t('Comment approved.'));
    $permalink_uri = $comment->permalink();
    $permalink_uri->setAbsolute();
    return new RedirectResponse($permalink_uri->toString());
  }

  /** * Redirects comment links to the correct page depending on comment settings. * * Since comments are paged there is no way to guarantee which page a comment * appears on. Comment paging and threading settings may be changed at any * time. With threaded comments, an individual comment may move between pages * as comments can be added either before or after it in the overall * discussion. Therefore we use a central routing function for comment links, * which calculates the page number based on current comment settings and * returns the full comment view with the pager set dynamically. * * @param \Symfony\Component\HttpFoundation\Request $request * The request of the page. * @param \Drupal\comment\CommentInterface $comment * A comment entity. * * @return \Symfony\Component\HttpFoundation\Response * The comment listing set to the page on which the comment appears. * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */
$this->assertNull($comment1->mail->value);

    // Confirm that the comment was created.     $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
    // Tests that markup is created for comment with heading.     $this->assertSession()->responseMatches('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|');
    // Tests that the comment's title link is the permalink of the comment.     $comment_permalink = $this->cssSelect('.permalink');
    $comment_permalink = $comment_permalink[0]->getAttribute('href');
    // Tests that the comment's title link contains the URL fragment.     $this->assertStringContainsString('#comment-' . $comment1->id()$comment_permalink, "The comment's title link contains the url fragment.");
    $this->assertEquals($comment1->permalink()->toString()$comment_permalink, "The comment's title has the correct link.");
  }

}

class CommentPermalinkFormatter extends StringFormatter {

  /** * {@inheritdoc} */
  protected function getEntityUrl(EntityInterface $comment) {
    /** @var \Drupal\comment\CommentInterface $comment */
    $comment_permalink = $comment->permalink();
    if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
      $attributes = $comment_permalink->getOption('attributes') ?: [];
      $attributes += ['title' => Unicode::truncate($body, 128)];
      $comment_permalink->setOption('attributes', $attributes);
    }
    return $comment_permalink;
  }

  /** * {@inheritdoc} */
  


    foreach ($commented_entity_ids as $entity_type => $ids) {
      $commented_entities[$entity_type] = $this->entityTypeManager
        ->getStorage($entity_type)
        ->loadMultiple($ids);
    }

    foreach ($comments as $comment) {
      /** @var \Drupal\Core\Entity\EntityInterface $commented_entity */
      $commented_entity = $commented_entities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()];
      $comment_permalink = $comment->permalink();
      if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
        $attributes = $comment_permalink->getOption('attributes') ?: [];
        $attributes += ['title' => Unicode::truncate($body, 128)];
        $comment_permalink->setOption('attributes', $attributes);
      }
      $options[$comment->id()] = [
        'title' => ['data' => ['#title' => $comment->getSubject() ?: $comment->id()]],
        'subject' => [
          'data' => [
            '#type' => 'link',
            '#title' => $comment->getSubject(),
            

    $this->submitForm($edit, 'Apply to selected items');
    $this->assertSession()->pageTextContains('Unapproved comments (0)');

    // Test message when no comments selected.     $this->drupalGet('admin/content/comment');
    $this->submitForm([], 'Apply to selected items');
    $this->assertSession()->pageTextContains('Select one or more comments to perform the update on.');

    // Test that comment listing shows the correct subject link.     $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [
      ':href' => $comments[0]->permalink()->toString(),
      ':title' => Unicode::truncate($comments[0]->get('comment_body')->value, 128),
      ':text' => $comments[0]->getSubject(),
    ]));

    // Verify that anonymous author name is displayed correctly.     $this->assertSession()->pageTextContains($author_name . ' (not verified)');

    // Test that comment listing shows the correct subject link.     $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [
      ':href' => $anonymous_comment4->permalink()->toString(),
      ':title' => Unicode::truncate($body, 128),
      
Home | Imprint | This part of the site doesn't use cookies.