View source
<?php
declare (strict_types=1);
use Dkd\PhpCmis\Data\PropertyInterface;
use Dkd\PhpCmis\Enum\PropertyType;
use Drupal\Core\Routing\RouteMatchInterface;
function cmis_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
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;
}
}
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,
],
],
];
}
function template_preprocess_cmis_browser(&$variables) {
$breadcrumbs = [
'#theme' => 'item_list',
'#items' => $variables['breadcrumbs'],
'#list_type' => 'ol',
'#attributes' => [
'class' => [
'breadcrumb',
],
],
'#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;
}
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);
}
}
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;
}
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 '';
}