Skip to content

Commit 2400fed

Browse files
author
dereuromark
committed
Add view annotations from controller helpers array.
1 parent 02e7eb3 commit 2400fed

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

config/app.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
],
1616
// Default View class to use
1717
'viewClass' => null,
18+
// Plugins to include for View annotations
19+
'includedPlugins' => [
20+
],
1821
// Always add annotations/meta even if not yet needed
1922
'preemptive' => false,
2023
// For meta file generator

docs/Annotations.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ class AppView extends View {
168168
}
169169
```
170170

171+
### Include plugins
172+
Using Configure key `'IdeHelper.includedPlugins'` you can set an array of (loaded!) plugins to include.
173+
Those will then also be parsed and all found helpers added to the AppView annotations.
174+
171175
## Components
172176
Components should annotate any component they use.
173177

src/Annotator/ViewAnnotator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ protected function _getHelpers() {
4242

4343
$plugin = null;
4444
$folders = App::path('Template', $plugin);
45+
$plugins = (array)Configure::read('IdeHelper.includedPlugins');
46+
foreach ($plugins as $plugin) {
47+
$folders = array_merge($folders, App::path('Template', $plugin));
48+
}
4549

4650
$this->helpers = [];
4751
foreach ($folders as $folder) {
@@ -106,9 +110,12 @@ protected function _parseHelpersInContent($content) {
106110
protected function _parseViewClass() {
107111
$helpers = [];
108112

109-
$className = App::className('App', 'View', 'View');
113+
$className = App::className('App', 'Controller', 'Controller');
114+
/** @var \App\Controller\AppController $Controller */
115+
$Controller = new $className();
110116
/** @var \App\View\AppView $View */
111-
$View = new $className();
117+
$View = $Controller->createView();
118+
112119
foreach ($View->helpers() as $alias => $helper) {
113120
$className = get_class($helper);
114121
if (strpos($className, 'Cake\\') === 0) {

0 commit comments

Comments
 (0)