You are here

private function CmisBrowser::prepareOperations in CMIS API 3.0.x

Same name and namespace in other branches
  1. 8.2 src/CmisBrowser.php \Drupal\cmis\CmisBrowser::prepareOperations()
  2. 8 src/CmisBrowser.php \Drupal\cmis\CmisBrowser::prepareOperations()

Prepare operation links.

Return value

array|string Return rendered element.

1 call to CmisBrowser::prepareOperations()
CmisBrowser::browse in src/CmisBrowser.php
Browse.

File

src/CmisBrowser.php, line 290

Class

CmisBrowser
Description of CmisBrowser.

Namespace

Drupal\cmis

Code

private function prepareOperations() {
  $create = [];
  $current_object_id = $this->current
    ->getId();
  if ($this->connection
    ->hasAllowableActionById($current_object_id, Action::CAN_CREATE_FOLDER)) {
    $create = [
      '/cmis/browser-create-folder/' => $this
        ->t('Create folder'),
    ];
  }
  $upload = [];
  if ($this->connection
    ->hasAllowableActionById($current_object_id, Action::CAN_CREATE_DOCUMENT)) {
    $upload = [
      '/cmis/browser-upload-document/' => $this
        ->t('Add document'),
    ];
  }
  $links = [];
  $routes = array_merge($create, $upload);
  if (isset($routes)) {
    foreach ($routes as $route => $title) {
      $url = Url::fromUserInput($route . $this->config . '/' . $current_object_id);
      $route_name = \Drupal::service('current_route_match')
        ->getRouteName();

      // Redirect Form to current page.
      if (strpos($route_name, 'browser') !== FALSE) {
        $url_destination = Url::fromRoute('cmis.cmis_repository_controller_browser', [
          'config' => $this->config,
          'folder_id' => $current_object_id,
        ]);
      }
      else {
        $url_destination = Url::fromRoute('<current>');
      }
      $link_options = [
        'query' => [
          'destination' => $url_destination
            ->toString(),
        ],
        'attributes' => [
          'class' => [
            'use-ajax',
          ],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'height' => 400,
            'width' => 700,
          ]),
        ],
      ];
      $url
        ->setOptions($link_options);
      $path = Link::fromTextAndUrl($title, $url)
        ->toRenderable();
      $links[] = [
        '#markup' => render($path),
        '#wrapper_attributes' => [
          'class' => [
            'object-properties',
          ],
        ],
      ];
    }
    $list = [
      '#theme' => 'item_list',
      '#items' => $links,
      '#type' => 'ul',
    ];
    return render($list);
  }
}