You are here

protected function CmisElement::prepare in CMIS API 8

Same name and namespace in other branches
  1. 8.2 src/CmisElement.php \Drupal\cmis\CmisElement::prepare()
  2. 3.0.x src/CmisElement.php \Drupal\cmis\CmisElement::prepare()

Prepare element data.

1 call to CmisElement::prepare()
CmisElement::setElement in src/CmisElement.php
Set element.

File

src/CmisElement.php, line 102

Class

CmisElement
Description of CmisElement

Namespace

Drupal\cmis

Code

protected function prepare() {
  $type_id = $this->element
    ->getBaseTypeId()
    ->__toString();
  $name = $this->element
    ->getName();
  $id = $this->element
    ->getId();
  $link_options = [];
  switch ($type_id) {
    case 'cmis:folder':
      switch ($this->type) {
        case 'browser':
          $url = \Drupal\Core\Url::fromUserInput('/cmis/browser/nojs/' . $this->config . '/' . $id);
          $link_options = [
            'attributes' => [
              'class' => [
                'use-ajax',
              ],
            ],
          ];
          break;
        case 'query':
          $url = \Drupal\Core\Url::fromUserInput('/cmis/browser/' . $this->config . '/' . $id);
          break;
      }
      if ($this->popup) {
        $link_options['query'] = [
          'type' => 'popup',
        ];
      }
      if (!empty($link_options)) {
        $url
          ->setOptions($link_options);
      }
      $link = \Drupal\Core\Link::fromTextAndUrl($name, $url)
        ->toRenderable();
      $this
        ->prepareElement('cmis_browser_folder_item', $link);
      break;
    case 'cmis:document':
      $this
        ->prepareElement('cmis_browser_document_item', $name, $id);
      break;
    default:
      $element = [
        '#theme' => 'cmis_browser_other_item',
        '#element' => $name,
      ];
      $this->data = [
        render($element),
      ];
  }
}