You are here

protected function TFTController::operation_links in Taxonomy File Tree 8

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

Return an <ul> with links for the current folder.

Return value

array The render array

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

File

src/Controller/TFTController.php, line 82

Class

TFTController
Class TFTController.

Namespace

Drupal\tft\Controller

Code

protected function operation_links($type, $id, $media = NULL, $gid = NULL) {
  $links = [];

  /** @var \Drupal\Core\TempStore\PrivateTempStore $tempstore */
  $tempstore = \Drupal::service('user.private_tempstore')
    ->get('tft');
  $query = 'destination=' . $tempstore
    ->get('q');
  switch ($type) {
    case 'folder':

      /** @var \Drupal\group\Entity\GroupInterface $group */
      $group = Group::load($gid);
      $user = $this
        ->currentUser();
      $edit = FALSE;

      // Hide edit link if the user has no access.
      if ($user
        ->hasPermission(TFT_ADD_TERMS) || $group && $group
        ->hasPermission(TFT_ADD_TERMS, $user)) {
        $edit = TRUE;
        $links[] = [
          '#type' => 'link',
          '#title' => $this
            ->t("edit"),
          '#url' => Url::fromUri("internal:/tft/term/edit/{$id}?" . $query),
          '#attributes' => [
            'class' => 'ops-link term-edit-link',
          ],
        ];
      }
      if ($user
        ->hasPermission(TFT_DELETE_TERMS) || $group && $group
        ->hasPermission(TFT_DELETE_TERMS, $user)) {
        if ($edit) {
          $links[] = [
            '#markup' => ' | ',
          ];
        }
        $links[] = [
          '#type' => 'link',
          '#title' => $this
            ->t("delete"),
          '#url' => Url::fromUri("internal:/tft/term/delete/{$id}?" . $query),
          '#attributes' => [
            'class' => 'ops-link term-edit-link',
          ],
        ];
      }
      break;
    case 'file':

      /** @var \Drupal\media\Entity\Media $media */
      if ($media
        ->access('update')) {
        $links[] = [
          '#type' => 'link',
          '#title' => $this
            ->t("edit"),
          '#url' => Url::fromUri("internal:/media/{$id}/edit?" . $query),
          '#attributes' => [
            'class' => 'ops-link node-edit-link',
          ],
        ];
        $links[] = [
          '#markup' => ' | ',
        ];
      }
      $links[] = [
        '#type' => 'link',
        '#title' => $this
          ->t("more info"),
        '#url' => Url::fromUri("internal:/media/{$id}"),
        '#attributes' => [
          'class' => 'ops-link',
        ],
      ];
      break;
  }
  return [
    'data' => $links,
  ];
}