You are here

cmis.module in CMIS API 8

Contains cmis.module.

File

cmis.module
View source
<?php

/**
 * @file
 * Contains cmis.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function cmis_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the cmis module.
    case 'help.page.cmis':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('CMIS implementation for interacting with a CMIS compliant repository') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_page_attachments().
 *
 * @param array $attachments
 */
function cmis_page_attachments(array &$attachments) {
  if (\Drupal::currentUser()
    ->hasPermission('access cmis browser')) {
    $attachments['#attached']['library'][] = 'core/drupal.ajax';
  }
}

/**
 * Implements hook_theme().
 */
function cmis_theme() {
  return array(
    'cmis_browser_folder_item' => array(
      'variables' => array(
        'element' => NULL,
      ),
      'template' => 'cmis-browser-folder-item',
    ),
    'cmis_browser_document_item' => array(
      'variables' => array(
        'element' => NULL,
        'mime_type' => NULL,
        'title' => NULL,
      ),
      'template' => 'cmis-browser-document-item',
    ),
    'cmis_browser_other_item' => array(
      'variables' => array(
        'element' => NULL,
      ),
      'template' => 'cmis-browser-other-item',
    ),
    'cmis_browser_document_details' => [
      'variables' => array(
        'title' => NULL,
        'mime_type' => NULL,
        'size' => NULL,
      ),
      'template' => 'cmis-browser-details',
    ],
    'cmis_browser' => array(
      'variables' => [
        'elements' => NULL,
        'header' => NULL,
        'breadcrumbs' => NULL,
        'operations' => NULL,
      ],
      'template' => 'cmis-browser',
    ),
    'cmis_content_properties' => array(
      'variables' => [
        'object' => NULL,
        'download' => NULL,
      ],
      'template' => 'cmis-content-properties',
    ),
    'cmis_object_delete_verify' => array(
      'variables' => [
        'title' => NULL,
        'description' => NULL,
        'link' => NULL,
      ],
      'template' => 'cmis-object-delete-verify',
    ),
    'cmis_query' => array(
      'variables' => [
        'elements' => NULL,
        'header' => NULL,
      ],
      'template' => 'cmis-query',
    ),
  );
}

/**
 * Template preprocess for cmis browser.
 * 
 * @param type $variables
 */
function template_preprocess_cmis_browser(&$variables) {
  if (!empty($variables['elements'])) {
    $breadcrumbs = [
      '#theme' => 'item_list',
      '#items' => $variables['breadcrumbs'],
      '#type' => 'ul',
    ];
    $variables['breadcrumbs'] = render($breadcrumbs);
    $table = array(
      '#theme' => 'table',
      '#header' => $variables['header'],
      '#rows' => $variables['elements'],
      '#sticky' => TRUE,
    );
    $variables['table'] = render($table);
  }
}

/**
 * Template preprocess for content properties.
 *
 * @param type $variables
 */
function template_preprocess_cmis_content_properties(&$variables) {
  $object = $variables['object'];
  $rows = [];
  foreach ($object
    ->getProperties() as $key => $property) {
    if ($property) {
      $rows[] = [
        $key,
        _cmis_get_property($key, $property),
      ];
    }
  }
  $variables['properties'] = '';
  if (!empty($rows)) {
    $table = [
      '#theme' => 'table',
      '#header' => [
        t('Property'),
        t('Value'),
      ],
      '#rows' => $rows,
    ];
    $variables['properties'] = render($table);
  }
}

/**
 * Get configuration entity to private variable.
 */
function cmis_get_configurations() {
  $storage = \Drupal::entityTypeManager()
    ->getStorage('cmis_connection_entity');
  $configs = $storage
    ->loadMultiple();
  $options = array(
    '_none' => t('None'),
  );
  foreach ($configs as $key => $config) {
    $options[$key] = $config
      ->get('label');
  }
  return $options;
}

/**
 * 
 * @param type $key
 * @param type $property
 * @return string
 */
function _cmis_get_property($key, $property) {
  $values = $property
    ->getValues();
  if (!empty($values)) {
    foreach ($values as &$value) {
      if (!empty($value) && ($key == 'cmis:creationDate' || $key == 'cmis:lastModificationDate')) {
        $value = $value
          ->format(\DateTime::ATOM);
      }
    }
    return implode(', ', $values);
  }
  return '';
}

Functions

Namesort descending Description
cmis_get_configurations Get configuration entity to private variable.
cmis_help Implements hook_help().
cmis_page_attachments Implements hook_page_attachments().
cmis_theme Implements hook_theme().
template_preprocess_cmis_browser Template preprocess for cmis browser.
template_preprocess_cmis_content_properties Template preprocess for content properties.
_cmis_get_property