element('/genericElements/SingleViews/single_view', [
* 'title' => '' //page title,
* 'description' => '' //description,
* 'description_html' => '' //html description, unsanitised,
* 'data' => $data, // the raw data passed for display
* 'fields' => [
* elements passed as to be displayed in the
element.
* format:
* [
'key' => '' // key to be displayed
* 'path' => '' // path for the value to be parsed
* 'type' => '' // generic assumed if not filled, uses SingleViews/Fields/* elements
* ]
* ],
* 'children' => [
* // Additional elements attached to the currently viewed object. index views will be appended via ajax calls below.
[
* 'title' => '',
* 'url' => '', //cakephp compatible url, can be actual url or array for the constructor
* 'collapsed' => 0|1 // defaults to 0, whether to display it by default or not
* 'loadOn' => 'ready|expand' // load the data directly or only when expanded from a collapsed state
*
* ],
* ]
* ]);
*
*/
$listElements = '';
if (!empty($fields)) {
foreach ($fields as $field) {
if (empty($field['type'])) {
$field['type'] = 'generic';
}
$listElements .= sprintf(
'%s | %s |
',
h($field['key']),
$this->element(
'/genericElements/SingleViews/Fields/' . $field['type'] . 'Field',
['data' => $data, 'field' => $field]
)
);
}
}
$metaTemplateTabs = '';
if (!empty($data['metaTemplates'])) {
$tabData = [
'navs' => [],
'content' => []
];
foreach($data['metaTemplates'] as $metaTemplate) {
if (!empty($metaTemplate->meta_template_fields)) {
$tabData['navs'][] = $metaTemplate->name;
$fieldsHtml = '';
foreach ($metaTemplate->meta_template_fields as $metaTemplateField) {
$metaField = $metaTemplateField->meta_fields[0];
$fieldsHtml .= sprintf(
'%s | %s |
',
h($metaField->field),
$this->element(
'/genericElements/SingleViews/Fields/genericField',
[
'data' => $metaField->value,
'field' => [
'raw' => $metaField->value
]
]
)
);
}
$fieldsHtml .= '
';
$tabData['content'][] = $fieldsHtml;
}
}
if (!empty($tabData['navs'])) {
$metaTemplateTabs = $this->Bootstrap->Tabs([
'pills' => true,
'card' => true,
'data' => $tabData
]);
}
}
$ajaxLists = '';
if (!empty($children)) {
foreach ($children as $child) {
$ajaxLists .= $this->element(
'/genericElements/SingleViews/child',
array(
'child' => $child,
'data' => $data
)
);
}
}
$title = empty($title) ?
__('{0} view', \Cake\Utility\Inflector::singularize(\Cake\Utility\Inflector::humanize($this->request->getParam('controller')))) :
$title;
echo sprintf(
'',
h($title),
empty($description) ? '' : sprintf('%s
', h($description)),
empty($description_html) ? '' : sprintf('%s
', $description_html),
$listElements,
$metaTemplateTabs,
$ajaxLists
);
?>