function ContextualLinks::render

Render the contextual fields.

Overrides FieldPluginBase::render

File

drupal/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php, line 71
Definition of Drupal\contextual\Plugin\views\field\ContextualLinks.

Class

ContextualLinks
Provides a handler that adds contextual links.

Namespace

Drupal\contextual\Plugin\views\field

Code

function render($values) {
  $links = array();
  foreach ($this->options['fields'] as $field) {
    if (empty($this->view->style_plugin->rendered_fields[$this->view->row_index][$field])) {
      continue;
    }
    $title = $this->view->field[$field]->last_render_text;
    $path = '';
    if (!empty($this->view->field[$field]->options['alter']['path'])) {
      $path = $this->view->field[$field]->options['alter']['path'];
    }
    if (!empty($title) && !empty($path)) {

      // Make sure that tokens are replaced for this paths as well.
      $tokens = $this
        ->get_render_tokens(array());
      $path = strip_tags(decode_entities(strtr($path, $tokens)));
      $links[$field] = array(
        'href' => $path,
        'title' => $title,
      );
      if (!empty($this->options['destination'])) {
        $links[$field]['query'] = drupal_get_destination();
      }
    }
  }
  if (!empty($links)) {
    $build = array(
      '#prefix' => '<div class="contextual">',
      '#suffix' => '</div>',
      '#theme' => 'links__contextual',
      '#links' => $links,
      '#attributes' => array(
        'class' => array(
          'contextual-links',
        ),
      ),
      '#attached' => array(
        'library' => array(
          array(
            'contextual',
            'contextual-links',
          ),
        ),
      ),
      '#access' => user_access('access contextual links'),
    );
    return drupal_render($build);
  }
  else {
    return '';
  }
}