2021-12-08 11:11:46 +01:00
< ? php
use \Cake\Routing\Router ;
2021-07-06 12:35:50 +02:00
$tabData = [
'navs' => [],
'content' => []
];
2021-11-05 17:03:11 +01:00
foreach ( $data [ 'MetaTemplates' ] as $metaTemplate ) {
2021-07-06 12:35:50 +02:00
if ( ! empty ( $metaTemplate -> meta_template_fields )) {
2021-12-08 11:11:46 +01:00
$tabData [ 'navs' ][] = [
'html' => $this -> element ( '/genericElements/MetaTemplates/metaTemplateNav' , [ 'metaTemplate' => $metaTemplate ])
];
2021-07-06 12:35:50 +02:00
$fields = [];
foreach ( $metaTemplate -> meta_template_fields as $metaTemplateField ) {
2021-11-05 17:03:11 +01:00
$labelPrintedOnce = false ;
2021-11-08 15:03:05 +01:00
if ( ! empty ( $metaTemplateField -> metaFields )) {
foreach ( $metaTemplateField -> metaFields as $metaField ) {
$fields [] = [
'key' => ! $labelPrintedOnce ? $metaField -> field : '' ,
2022-11-09 14:01:37 +01:00
'raw' => $metaField -> value ,
'warning' => $metaField -> warning ? ? null ,
'info' => $metaField -> info ? ? null ,
'danger' => $metaField -> danger ? ? null
2021-11-08 15:03:05 +01:00
];
$labelPrintedOnce = true ;
}
2021-11-05 17:03:11 +01:00
}
2021-07-06 12:35:50 +02:00
}
$listTable = $this -> Bootstrap -> listTable ([
'hover' => false ,
'elementsRootPath' => '/genericElements/SingleViews/Fields/'
],[
'item' => false ,
2021-11-08 15:03:05 +01:00
'fields' => $fields ,
'caption' => __n (
'This meta-template contains {0} meta-field' ,
'This meta-template contains {0} meta-fields' ,
count ( $fields ),
count ( $fields )
)
2021-07-06 12:35:50 +02:00
]);
2021-12-17 14:04:44 +01:00
if ( ! empty ( $metaTemplate [ 'hasNewerVersion' ]) && ! empty ( $fields )) {
2021-12-08 11:11:46 +01:00
$listTable = $this -> Bootstrap -> alert ([
'html' => sprintf (
'<div>%s</div><div>%s</div>' ,
__ ( 'These meta-fields are registered under an outdated template. Newest template is {0}, current is {1}.' , $metaTemplate [ 'hasNewerVersion' ] -> version , $metaTemplate -> version ),
$this -> Bootstrap -> button ([
'text' => __ ( 'Migrate to version {0}' , $metaTemplate [ 'hasNewerVersion' ] -> version ),
'variant' => 'success' ,
'nodeType' => 'a' ,
2022-11-24 12:50:11 +01:00
'attrs' => [
2021-12-08 11:11:46 +01:00
'href' => Router :: url ([
'controller' => 'metaTemplates' ,
'action' => 'migrateOldMetaTemplateToNewestVersionForEntity' ,
$metaTemplate -> id ,
$data -> id ,
])
]
])
),
'variant' => 'warning' ,
]) . $listTable ;
}
2021-07-06 12:35:50 +02:00
$tabData [ 'content' ][] = $listTable ;
}
}
if ( ! empty ( $additionalTabs )) {
$tabData [ 'navs' ] = array_merge ( $additionalTabs [ 'navs' ], $tabData [ 'navs' ]);
$tabData [ 'content' ] = array_merge ( $additionalTabs [ 'content' ], $tabData [ 'content' ]);
}
if ( ! empty ( $tabData [ 'navs' ])) {
$metaTemplateTabs = $this -> Bootstrap -> Tabs ([
'pills' => true ,
'card' => true ,
'body-class' => [ 'p-1' ],
'data' => $tabData
]);
}
echo $metaTemplateTabs ;