-
Modifying a DCA
I've done quite a bit of modifying DCAs in the past and I've generally gone by the rule that if I want to modify a DCA I need to add a file with the dca name in a directory that will appear after the existing DCA.
Is there any way to dynamically modify the DCA at any point?
Ie if I had files in modules/aaa to modify files in modules/backend ?
-
Re: Modifying a DCA
You might want to make sure that folder comes alphabetically after "backend" (since modules are loaded in alphabetical order). If you put it at the end (e.g. "modules/z_aaa/"), you'll have free reign over dynamically changing the DCA without worrying about other modules coming along and overwriting your changes.
You can use the "loadDataContainer" hook (http://www.contao.org/hooks.html#loadDataContainer).
What you'd do is check the first parameter that is passed against a list of changes you want to make, e.g.
Code:
if ($strName === 'tl_content')
And then make your changes directly to the data container array, e.g.
Code:
unset($GLOBALS['TL_DCA']['tl_content']['list']['operations']['show']);
The "if" statement isn't technically necessary for it to work, but it will allow you to make a change only when you need to, and to only do it once per page load.
As an additional optimization, you may also want to check against "$this->Config->getActiveModules()" to only change when a module is active. But this doesn't apply to your specific example (since you can't disable "backend" in the settings).
Hope this helps.
-
Re: Modifying a DCA
I'm trying to get away from using files to modify DCAs but rather do it in code execution, will give the hook a quick try and see if it works.
-
Re: Modifying a DCA
Peter have a look at formAuto extension:
Code:
$GLOBALS['TL_DCA']['tl_form_auto'] = array
(
// Config
'config' => array
(
'dataContainer' => 'DynamicTable',
'ptable' => 'tl_form',
'switchToEdit' => false,
'enableVersioning' => false,
'oncreate_callback' => array
(
array('FormAuto', 'initializeFormAuto'),
)
)
);
With DynamicTable your are able to define dynamic DCA