Skip to content
LinkReply.php 1.22 KiB
Newer Older
 * Contains \Drupal\comment\Plugin\views\field\LinkReply.
use Drupal\Component\Annotation\PluginID;
 * Field handler to present a link to reply to a comment.
 *
 * @ingroup views_field_handlers
 */
class LinkReply extends Link {
    //check for permission to reply to comments
    return user_access('post comments');
  }

  /**
   * Prepare the link for replying to the comment.
   *
   * @param \Drupal\Core\Entity\EntityInterface $data
   *   The comment entity.
   * @param \Drupal\views\ResultRow $values
   *   The values retrieved from a single row of a view's query result.
   *
   * @return string
   *   Returns a string for the link text.
   */
  protected function renderLink($data, ResultRow $values) {
    $text = !empty($this->options['text']) ? $this->options['text'] : t('Reply');
    $comment = $this->getEntity($values);

    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['path'] = "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->value}/{$comment->field_name->value}/{$comment->id()}";