function File::renderLink

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

Prepares link to the file.

Parameters

string $data: The XSS safe string for the link text.

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string Returns a string for the link text.

1 call to File::renderLink()
File::render in core/modules/file/src/Plugin/views/field/File.php
Renders the field.

File

core/modules/file/src/Plugin/views/field/File.php, line 64

Class

File
Field handler to provide simple renderer that allows linking to a file.

Namespace

Drupal\file\Plugin\views\field

Code

protected function renderLink($data, ResultRow $values) {
    if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
        $this->options['alter']['make_link'] = TRUE;
        // @todo Wrap in file_url_transform_relative(). This is currently
        // impossible. As a work-around, we could add the 'url.site' cache context
        // to ensure different file URLs are generated for different sites in a
        // multisite setup, including HTTP and HTTPS versions of the same site.
        // But unfortunately it's impossible to bubble a cache context here.
        // Fix in https://www.drupal.org/node/2646744.
        $this->options['alter']['path'] = file_create_url($this->getValue($values, 'uri'));
    }
    return $data;
}

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