You are here

public function FileBrowserPreview::render in File Entity Browser 8

Renders the field.

Parameters

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

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/FileBrowserPreview.php, line 20

Class

FileBrowserPreview
Defines a custom field that renders a preview of a file, for the purposes of.

Namespace

Drupal\file_browser\Plugin\views\field

Code

public function render(ResultRow $values) {

  /** @var \Drupal\file\Entity\File $file */
  $file = $this
    ->getEntity($values);
  $build = [];
  $build['image'] = $this
    ->getFilePreview($file, 'file_entity_browser_thumbnail');
  $build['preview'] = [
    '#title' => $this
      ->t('Preview'),
    '#type' => 'link',
    '#url' => Url::fromRoute('file_browser.preview', [
      'file' => $file
        ->id(),
    ]),
    '#attributes' => [
      'class' => [
        'file-browser-preview-button',
        'use-ajax',
      ],
      'data-dialog-type' => 'modal',
      'data-dialog-options' => '{"classes": {"ui-dialog": "ui-corner-all file-browser-preview-dialog"}, "show": "fadeIn", "hide": "fadeOut"}',
    ],
  ];
  return $build;
}