diff options
Diffstat (limited to 'fai_gestion/plugins/CustomTheme/config/bootstrap.php')
-rw-r--r-- | fai_gestion/plugins/CustomTheme/config/bootstrap.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/fai_gestion/plugins/CustomTheme/config/bootstrap.php b/fai_gestion/plugins/CustomTheme/config/bootstrap.php index 7215ce7..351e582 100644 --- a/fai_gestion/plugins/CustomTheme/config/bootstrap.php +++ b/fai_gestion/plugins/CustomTheme/config/bootstrap.php @@ -20,6 +20,7 @@ **/ use Cake\Event\Event; use Cake\Event\EventManager; +use Cake\Utility\Inflector; // https://book.cakephp.org/3.0/en/bake/development.html @@ -52,6 +53,36 @@ EventManager::instance()->on('Bake.beforeRender.Model.table', function (Event $e if ( $view->BakeExtra->hasFilters($controllerName) ) { $view->viewVars['behaviors'] += ['Search.Search' => [] ]; } + $titleOpts = $view->BakeExtra->getTitleOpts($controllerName); + // Force displayField to be the custom title if any defined in bake_extra.php + if ( is_array($titleOpts) ) { + $view->viewVars['displayField'] = 'title'; + } +}); + +EventManager::instance()->on('Bake.beforeRender.Model.entity', function (Event $event) { + $view = $event->getSubject(); + // Set template variables for virtual title if any defined in bake_extra.php + $controllerName = Inflector::pluralize($view->viewVars['name']); + $titleOpts = $view->BakeExtra->getTitleOpts($controllerName); + + // viewVars are kept from one entity to another (Cake bug ?) + unset($view->viewVars['virtualTitleGlue']); + unset($view->viewVars['virtualTitlePieces']); + unset($view->viewVars['virtualTitleCustomCode']); + + if ( is_array($titleOpts) ) { + foreach ($titleOpts as $k => $v) { + // For pieces array, prefix each item to have '$this->col_name' + if ( $k === 'pieces' && is_array($v) ) { + $v = preg_filter('/^/', '$this->', $v); + } + // Prefix each key (less view namespace problems and get more explcit in .twig + $k = 'virtualTitle'.Inflector::camelize($k); + // Export options to the view + $view->viewVars[$k] = $v; + } + } }); /* * Note : "cake bake all" behavior is customized in |