function ContactLink::renderLink

Same name in other branches
  1. 9 core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink::renderLink()
  2. 8.9.x core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink::renderLink()
  3. 11.x core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink::renderLink()

Overrides LinkBase::renderLink

File

core/modules/contact/src/Plugin/views/field/ContactLink.php, line 43

Class

ContactLink
Defines a field that links to the user contact page, if access is permitted.

Namespace

Drupal\contact\Plugin\views\field

Code

protected function renderLink(ResultRow $row) {
    $entity = $this->getEntity($row);
    if (!$entity) {
        return '';
    }
    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['url'] = $this->getUrlInfo($row);
    $title = $this->t('Contact %user', [
        '%user' => $entity->label(),
    ]);
    $this->options['alter']['attributes'] = [
        'title' => $title,
    ];
    if (!empty($this->options['text'])) {
        return $this->options['text'];
    }
    else {
        return $title;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.