You are here

protected function TFTController::link in Taxonomy File Tree 8

Same name and namespace in other branches
  1. 3.x src/Controller/TFTController.php \Drupal\tft\Controller\TFTController::link()

Format a folder or file link.

Return value

array Render array with the formatted link

1 call to TFTController::link()
TFTController::get_content in src/Controller/TFTController.php
Returns folder content.

File

src/Controller/TFTController.php, line 34

Class

TFTController
Class TFTController.

Namespace

Drupal\tft\Controller

Code

protected function link($item, $mime, $type = NULL) {
  if ($mime == 'folder') {
    return [
      'data' => [
        '#type' => 'link',
        '#title' => $item['name'],
        '#url' => Url::fromUri("internal:#term/{$item['id']}"),
        '#attributes' => [
          'class' => 'folder-folder-link',
          'id' => "tid-{$item['id']}",
        ],
      ],
    ];
  }
  elseif ($type && $type == 'record') {

    // Moxtra recording file.
    // Get the filefield icon.
    $icon_class = file_icon_class($mime);
    return [
      'data' => [
        '#type' => 'link',
        '#title' => $item['name'],
        '#url' => Url::fromUri("internal:/tft/download/file/{$item['id']}"),
        '#attributes' => [
          'class' => "file {$icon_class}",
          'target' => '_blank',
        ],
      ],
    ];
  }
  else {
    $media = Media::load($item['id']);
    $view_builder = \Drupal::entityTypeManager()
      ->getViewBuilder($media
      ->getEntityTypeId());
    return [
      'data' => [
        $view_builder
          ->view($media),
      ],
    ];
  }
}