function Extension::render

Render the field.

Parameters

$values: The values retrieved from the database.

Overrides FieldPluginBase::render

File

drupal/core/modules/file/lib/Drupal/file/Plugin/views/field/Extension.php, line 44
Definition of views_handler_field_file_extension.

Class

Extension
Returns a pure file extension of the file, for example 'module'.

Namespace

Drupal\file\Plugin\views\field

Code

function render($values) {
  $value = $this
    ->getValue($values);
  if (!$this->options['extension_detect_tar']) {
    if (preg_match('/\\.([^\\.]+)$/', $value, $match)) {
      return $this
        ->sanitizeValue($match[1]);
    }
  }
  else {
    $file_parts = explode('.', basename($value));

    // If there is an extension.
    if (count($file_parts) > 1) {
      $extension = array_pop($file_parts);
      $last_part_in_name = array_pop($file_parts);
      if ($last_part_in_name === 'tar') {
        $extension = 'tar.' . $extension;
      }
      return $this
        ->sanitizeValue($extension);
    }
  }
}