You are here

cmis.module in CMIS API 8.2

File

cmis.module
View source
<?php

/**
 * @file
 * Contains hook implementations for CMIS module.
 */
declare (strict_types=1);
use Dkd\PhpCmis\Data\PropertyInterface;
use Dkd\PhpCmis\Enum\PropertyType;
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;
  }
}

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

/**
 * Implements hook_preprocess_cmis_browser().
 */
function template_preprocess_cmis_browser(&$variables) {
  $breadcrumbs = [
    '#theme' => 'item_list',
    '#items' => $variables['breadcrumbs'],
    '#list_type' => 'ol',
    // In case the theme is using an item-list template without wrapper.
    '#attributes' => [
      'class' => [
        'breadcrumb',
      ],
    ],
    // In case the theme is using an item-list template with a wrapper, such as
    // Bartik which also force an 'item-list' class.
    '#wrapper_attributes' => [
      'class' => [
        'breadcrumb',
        'js-cmis-breadcrumb',
      ],
    ],
  ];
  $variables['breadcrumbs'] = $breadcrumbs;
  $variables['#attached']['library'][] = 'core/drupal.ajax';
  $table = [
    '#theme' => 'table',
    '#header' => $variables['header'],
    '#rows' => $variables['elements'],
    '#empty' => t('This folder is empty.'),
    '#sticky' => TRUE,
  ];
  $variables['table'] = $table;
}

/**
 * Implements hook_preprocess_cmis_content_properties().
 */
function template_preprocess_cmis_content_properties(&$variables) {
  $object = $variables['object'];
  $rows = [];
  foreach ($object
    ->getProperties() as $key => $property) {
    if ($property) {
      $rows[] = [
        $key,
        _cmis_get_property($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 = [
    '_none' => t('None'),
  ];
  foreach ($configs as $key => $config) {
    $options[$key] = $config
      ->get('label');
  }
  return $options;
}

/**
 * Helper function.
 *
 * @param \Dkd\PhpCmis\Data\PropertyInterface $property
 *   The property to get values from.
 *
 * @return string
 *   The property key's value.
 */
function _cmis_get_property(PropertyInterface $property) {
  $values = $property
    ->getValues();
  $type = $property
    ->getType();
  if (!empty($values)) {
    foreach ($values as &$value) {
      if (!empty($value) && $type
        ->equals(PropertyType::DATETIME)) {
        $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_theme Implements hook_theme().
template_preprocess_cmis_browser Implements hook_preprocess_cmis_browser().
template_preprocess_cmis_content_properties Implements hook_preprocess_cmis_content_properties().
_cmis_get_property Helper function.