MODx Version 2.2.5-pl
When creating new Resource, TVs did not load correctly when we change default template on the fly, either using Plugin or Form Customization.
For example:
- create a "folderTemplate" template, and attach some TVs into it (example we attach "folderTV")
- create a "childTemplate" template, and attach some TVs into it (example we attach "childTV")
- create a Form Customization (with resource/create rule set) to set child resource of "folderTemplate" by default use "childTemplate", or we can create a plugin to set it programmatically.
- create a Container with "folderTemplate" as its template.
Then try to create a new resource under the newly created Container. The template by default loaded correctly (childTemplate), but the TVs loaded incorrectly. Instead of displaying "childTV", the resource panel displaying "folderTV".
Here what I found on
modx/manager/controller/default/resource/create.class.php that extend base class
modx/manager/controller/default/resource/resource.class.php
DEBUG OUTPUT
Assume folderTemplate's id=9, and childTemplate's id=10.
#log-1: manager/controllers/default/resource/create.class.php line 85
- function proccess -> $this->resource->get('template') before fireOnRenderEvent
return template: 0
#log-2: manager/controllers/default/resource/create.class.php line 98
- function process -> call function getDefaultTemplate
return defaultTemplate: 9
#log-3: manager/controllers/default/resource/create.class.php line 121
- function process -> get checkFormCustomizationRules()
return $overridden template: 10
#log-4: manager/controllers/default/resource/create.class.php line 147
- function process -> $this->resourceArray['template']
return template: 10
- function process -> $this->resource->get('template')
return template: 9
#log-5: manager/controllers/default/resource/resource.class.php line 263
- loadTVs:this->resource->get('template'): 9
When creating a new resource, the default $resource::get template=0, that's correct (Log-1). Template remain 0, until just before
fireOnRenderEvent.
So a plugin with OnDocFormRender event can change the template with
$resource->set('template', n), where "n" is template ID.
If the template did not change, then it's search for parent container and get it's template (defaultTemplate=9), that' correct (log-2).
Still on function process at create.class.php, it's search for FormCustomizationRules and get expected overridden template: 10, that's correct (log-3).
Log-4 show that resourceArray has been overridden; then it will be outputed to html as jSON with template: 10, its correct (log-4a). But somehow its forgot to also override $resource object. (log-4b)
At last, function process make a call to
loadTVs function, but the loadTVs function wrongly output the TVs because it get the template from $resource->get('template') not from $resourceArray['template']. (log-5)
[ed. note: lokamaya last edited this post 13 years, 10 months ago.]