class CmisElement in CMIS API 3.0.x
Same name and namespace in other branches
- 8.2 src/CmisElement.php \Drupal\cmis\CmisElement
- 8 src/CmisElement.php \Drupal\cmis\CmisElement
Description of CmisElement.
Hierarchy
- class \Drupal\cmis\CmisElement uses StringTranslationTrait
Expanded class hierarchy of CmisElement
1 file declares its use of CmisElement
- CmisQueryForm.php in src/
Form/ CmisQueryForm.php
File
- src/
CmisElement.php, line 17
Namespace
Drupal\cmisView source
class CmisElement {
use StringTranslationTrait;
/**
* Cmis element.
*
* @var object
*/
private $element;
/**
* Config.
*
* @var string
*/
private $config;
/**
* Popup flag.
*
* @var string
*/
private $popup;
/**
* Element parent id.
*
* @var string
*/
private $parent;
/**
* The query string from cmis query form.
*
* @var string
*/
private $queryString;
/**
* Render array of element.
*
* @var array
*/
private $data = [];
/**
* The type of caller.
*
* @var string
*/
private $type;
/**
* Root folder id.
*
* @var object
*/
private $rootId;
/**
* {@inheritdoc}
*
* @param string $config
* Entity label.
* @param bool $popup
* Get true if is a popup.
* @param \Dkd\PhpCmis\DataObjects\AbstractFileableCmisObject $parent
* Get AbstractFileableCmisObject class.
* @param string $query
* CMIS Query.
* @param string $root_id
* CMIS root id.
*/
public function __construct($config, $popup = FALSE, AbstractFileableCmisObject $parent = NULL, $query = '', $root_id = '') {
$this->config = $config;
$this->popup = $popup;
$this->parent = $parent;
$this->queryString = $query;
$this->rootId = $root_id;
}
/**
* Set element.
*
* @param string $type
* Controller type.
* @param \Dkd\PhpCmis\DataObjects\AbstractFileableCmisObject $element
* Get AbstractFileableCmisObject class.
*/
public function setElement($type, AbstractFileableCmisObject $element) {
$this->type = $type;
$this->element = $element;
$this
->prepare();
}
/**
* Prepare element data.
*/
protected function prepare() {
$type_id = $this->element
->getBaseTypeId()
->__toString();
$name = $this->element
->getName();
$id = $this->element
->getId();
switch ($type_id) {
case 'cmis:folder':
$this
->prepareElement('cmis_browser_folder_item', $name, $id);
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),
];
}
}
/**
* Get element data.
*
* @return array
* Return data object.
*/
public function getData() {
return $this->data;
}
/**
* Set element to render array.
*
* @param string $theme
* Render theme.
* @param string $data
* Data.
* @param string $id
* CMIS Object id.
*/
protected function prepareElement($theme, $data, $id = '') {
$author = $this->element
->getCreatedBy();
$created = $this->element
->getCreationDate()
->format('Y-m-d H:i:s');
$description = $this->element
->getDescription();
$title = '';
if ($title_property = $this->element
->getProperty('cm:title')) {
$title = $title_property
->getFirstValue();
}
$size = 0;
if ($size_property = $this->element
->getProperty('cmis:contentStreamLength')) {
$size = $size_property
->getFirstValue();
}
$mime_type = '';
$operations = '';
if ($theme == 'cmis_browser_folder_item') {
$this
->prepareFolderElement($data, $operations, $id);
}
if ($theme == 'cmis_browser_document_item') {
$this
->prepareDocumentElement($data, $operations, $id);
}
if (!$this->popup) {
$this
->preparePropertiesLink($operations);
}
$element = [
'#theme' => $theme,
'#element' => $data,
];
$details = [
'#theme' => 'cmis_browser_document_details',
'#title' => $title,
'#mime_type' => $mime_type,
'#size' => number_format($size, 0, '', ' '),
];
$this->data = [
render($element),
render($details),
$author,
$created,
$description,
$operations,
];
}
/**
* Prepare document element.
*
* @param string $data
* Get data.
* @param string $operations
* Get render.
* @param string $id
* CMIS object id.
*/
private function prepareDocumentElement(&$data, &$operations, $id) {
if ($this->popup) {
$url = Url::fromUserInput('/');
$link_options = [
'attributes' => [
'class' => [
'cmis-field-insert',
],
'id' => $this->element
->getProperty('cmis:objectId')
->getFirstValue(),
'name' => $data,
],
];
$url
->setOptions($link_options);
$path = Link::fromTextAndUrl($this
->t('Choose'), $url)
->toRenderable();
$operations = render($path);
}
$url = Url::fromUserInput('/cmis/document/' . $this->config . '/' . $id);
$path = Link::fromTextAndUrl($data, $url)
->toRenderable();
$data = [
'#markup' => render($path),
];
}
/**
* Prepare folder element.
*
* @param string $data
* Get data.
* @param string $operations
* Get render.
* @param string $id
* CMIS object id.
*/
private function prepareFolderElement(&$data, &$operations, $id) {
switch ($this->type) {
case 'browser':
$url = Url::fromUserInput('/cmis/browser/nojs/' . $this->config . '/' . $id);
$link_options = [
'attributes' => [
'class' => [
'use-ajax',
],
],
];
break;
case 'query':
$url = Url::fromUserInput('/cmis/browser/' . $this->config . '/' . $id);
break;
}
if ($this->popup) {
$url_operation = Url::fromUserInput('/');
$link_options_operations = [
'attributes' => [
'class' => [
'cmis-field-insert',
],
'id' => $this->element
->getProperty('cmis:objectId')
->getFirstValue(),
'name' => $data,
],
];
$url_operation
->setOptions($link_options_operations);
$path = Link::fromTextAndUrl($this
->t('Choose folder'), $url_operation)
->toRenderable();
$operations = render($path);
$link_options['query'] = [
'type' => 'popup',
];
}
if (!empty($link_options)) {
$url
->setOptions($link_options);
}
$data = Link::fromTextAndUrl($data, $url)
->toRenderable();
}
/**
* Prepare properties link.
*
* @param string $operations
* Get render.
*/
private function preparePropertiesLink(&$operations) {
$url = Url::fromUserInput('/cmis/object-properties/' . $this->config . '/' . $this->element
->getId());
$link_options = [
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'height' => 400,
'width' => 700,
]),
],
];
$url
->setOptions($link_options);
$path = Link::fromTextAndUrl($this
->t('Properties'), $url)
->toRenderable();
$links[] = [
'#markup' => render($path),
'#wrapper_attributes' => [
'class' => [
'object-properties',
],
],
];
$cmis_connection_api = new CmisConnectionApi($this->config);
$cmis_connection_api
->setDefaultParameters();
$element_id = $this->element
->getId();
if ($this->rootId != $element_id && $cmis_connection_api
->hasAllowableActionById($element_id, Action::CAN_DELETE_OBJECT)) {
$url = Url::fromUserInput('/cmis/object-delete-verify/' . $this->config . '/' . $element_id);
$link_options = [
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'height' => 120,
'width' => 600,
]),
],
'query' => [
'type' => $this->type,
],
];
switch ($this->type) {
case 'browser':
$link_options['query']['parent'] = $this->parent
->getId();
break;
case 'query':
$link_options['query']['query_string'] = $this->queryString;
break;
}
$url
->setOptions($link_options);
$path = Link::fromTextAndUrl($this
->t('Delete'), $url)
->toRenderable();
$links[] = [
'#markup' => render($path),
'#wrapper_attributes' => [
'class' => [
'object-delete',
],
],
];
}
$list = [
'#theme' => 'item_list',
'#items' => $links,
'#type' => 'ul',
];
$operations = render($list);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CmisElement:: |
private | property | Config. | |
CmisElement:: |
private | property | Render array of element. | |
CmisElement:: |
private | property | Cmis element. | |
CmisElement:: |
private | property | Element parent id. | |
CmisElement:: |
private | property | Popup flag. | |
CmisElement:: |
private | property | The query string from cmis query form. | |
CmisElement:: |
private | property | Root folder id. | |
CmisElement:: |
private | property | The type of caller. | |
CmisElement:: |
public | function | Get element data. | |
CmisElement:: |
protected | function | Prepare element data. | |
CmisElement:: |
private | function | Prepare document element. | |
CmisElement:: |
protected | function | Set element to render array. | |
CmisElement:: |
private | function | Prepare folder element. | |
CmisElement:: |
private | function | Prepare properties link. | |
CmisElement:: |
public | function | Set element. | |
CmisElement:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |