You are here

function ContactLink::render_link in Views (for Drupal 7) 8.3

Overrides Link::render_link

File

lib/Views/contact/Plugin/views/field/ContactLink.php, line 39
Definition of Views\contact\Plugin\views\field\ContactLink.

Class

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

Namespace

Views\contact\Plugin\views\field

Code

function render_link($data, $values) {
  global $user;
  $uid = $this
    ->get_value($values, 'uid');
  if (empty($uid)) {
    return;
  }
  $account = user_load($uid);
  if (empty($account)) {
    return;
  }

  // Check access when we pull up the user account so we know
  // if the user has made the contact page available.
  $menu_item = menu_get_item("user/{$uid}/contact");
  if (!$menu_item['access'] || empty($account->data['contact'])) {
    return;
  }
  $this->options['alter']['make_link'] = TRUE;
  $this->options['alter']['path'] = 'user/' . $account->uid . '/contact';
  $this->options['alter']['attributes'] = array(
    'title' => t('Contact %user', array(
      '%user' => $account->name,
    )),
  );
  $text = $this->options['text'];
  return $text;
}