You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-6
Original file line number
Diff line number
Diff line change
@@ -52,9 +52,11 @@ view template as far as possible. We want to achieve that within the controller
52
52
53
53
**6. Allow configuration of a global default layout for each layout scheme**
54
54
55
-
**7. [TODO] Default (child) ViewModel variables (fixed and custom computed)**
55
+
**7. Provide hooks for pre- and postprocessing**
56
56
57
-
In the current version you can either assign the layout variables within the controller action via `layoutScheme` controller plugin. Alternatively you may supply an event handler for postprocessing. We provide an example here.
57
+
**8. Provide a controller plugin to control scheme selection and setup of layout variables**
58
+
59
+
In the current version you can either assign the layout variables within the controller action via `layoutScheme` controller plugin. Alternatively you may supply an event handler for pre- and postprocessing. We provide an example here.
58
60
59
61
Installation
60
62
------------
@@ -126,7 +128,7 @@ How MxcLayoutScheme works
126
128
1. On Bootstrap MxcLayoutScheme hooks into the dispatch event of the application's EventManager with low priority (-1000).
127
129
2. On Bootstrap MxcLayoutScheme instantiates the controller plugin `'layoutScheme'` to inject a reference to the application's ServiceManager instance.
128
130
2. On dispatch MxcLayoutScheme evaluates the current route matched, the module name, the controller name and the action name.
129
-
3. Then MxcLayoutScheme triggers an `MxcLayoutSchemeService::HOOK_PRE_SCHEME_SELECT` event. If you registered an event handler for that event in the bootstrap somewhere you can set the active scheme with `$e->getTarget()->setActiveScheme($schemeName)` with a `$schemeName`of your choice.
131
+
3. Then MxcLayoutScheme triggers an `MxcLayoutSchemeService::HOOK_PRE_SELECT_SCHEME` event. If you registered an event handler for that event in the bootstrap somewhere you can set the active scheme with `$e->getTarget()->setActiveScheme($schemeName)` with a `$schemeName`of your choice. Alternatively, you can set the active scheme within the controller action using the controller plugin: `$this->layoutScheme()->setActiveScheme($schemeName)`.
130
132
4. Then, MxcLayoutScheme loads the currently active scheme.
131
133
5. MxcLayoutScheme checks the `route_layouts` for a key matching the matched route name. If the key exists the layout template registered to that match gets applied. If the rule defines child view models they get merged with the (optionally) defined default child view models and get applied to the layout. Go to 10.
132
134
6. MxcLayoutScheme then checks the `mca_layouts` for a key matching Module\Conroller\Action. If the key exists the layout template registered to that match gets applied. If the rule defines child view models they get merged with the (optionally) defined default child view models and get applied to the layout. Go to 10.
@@ -151,7 +153,7 @@ Example Event Handler to choose the active scheme
@@ -297,9 +299,24 @@ From within a controller action you can access the controller plugin with `$this
297
299
298
300
`layoutScheme` provides the following interfaces:
299
301
302
+
300
303
**getChildViewModel($capture):** returns the child view model registered for the $capture capture. Null if capture is not registered.
304
+
301
305
**getChildViewModels():** returns the array of child view models like `array ( 'capture' => ViewModel )`
302
-
**setVariables($param):** see ViewModels `setVariables` for $param specification. The `layoutScheme setVariables` function applies the same variables provided through $params to the controller's layout and to all registered child ViewModels.
306
+
307
+
**setVariables($variables, $override = false):** see ViewModels `setVariables` for parameter specification. The `layoutScheme setVariables` function applies the same variables provided through `$variables` to the controller's layout and to all registered child ViewModels.
308
+
309
+
**getActiveScheme():** get the currently active layout scheme.
310
+
311
+
**setActiveScheme($schemeName, $skipPreSelectSchemeEvent = false):** set the layout scheme to use. Set `skipPreSelectSchemeEvent` to `true` then the `LayoutSchemeService::HOOK_PRE_SELECT_EVENT` will not get triggered by `LayoutSchemeService`.
312
+
313
+
**skipPreSelectSchemeEvent():** disable triggering of `LayoutSchemeService::HOOK_PRE_SELECT_SCHEME` this time. This event would get triggered after the view action before rendering. You may want to disable the event to prevent the global event handler to override the active scheme you set via `$this->layoutScheme()->setActiveScheme()`.
314
+
######Note:
315
+
The event is not skipped by default. Within the global event handler you can check if the active scheme was set by the controller plugin using `LayoutSchemeService->hasPluginSetActiveScheme()` to prevent overriding.
316
+
317
+
**skipPostSelectLayoutEvent():** disable triggering of `LayoutSchemeService::HOOK_POST_SELECT_LAYOUT` this time.
318
+
319
+
**hasPluginSetActiveScheme()**: returns `true` if the active scheme was set previously through by the user through `layoutScheme()->setActiveScheme($schemeName)`.
303
320
304
321
#####Note
305
322
@@ -310,6 +327,17 @@ Example:
310
327
$this->layout()->setVariables($varMain); // assign variables to the layout's ViewModel
311
328
$this->layoutScheme()->getChildViewModel('panelLeft')->setVariables($varPanelLeft); // assign variables to leftPanel child
312
329
330
+
Important:
331
+
332
+
`LayoutSchemeService` registers to the `MvcEvent::EVENT_DISPATCH` with priority of -1000. So layout selection
333
+
happens *after* your controller action has returned *before* the page gets rendered. This means in particular that at the time the controller action is executed the `LayoutSchemeService` does not know anything about the layout selected and it's child view models.
334
+
335
+
If you call for example `layoutScheme()->getChildViewModel("footer")` this would return nothing because the footer child ViewModel has not been computed yet.
336
+
337
+
`LayoutSchemeService` is designed for early execution of the onDispatch event handler if called via the controller plugin. If early event handling is done the service prevents event processing to happen again when triggered globally afterwards. Even in early processing the service triggers the `HOOK_PRE_SELECT_SCHEME` and `HOOK_POST_SELECT_LAYOUT` events.
338
+
339
+
If you do not want one or both events to get triggered make sure to call `layoutScheme()->skipPostSelectLayoutEvent()` and/or `layoutScheme()->skipPreSelectSchemeEvent()` *before* you call `getChildViewModel()`, `getChildViewModels()` or `setVariables()`. Otherwise the event(s) will get fired.
0 commit comments