It would help if I put the original code in the post, not the experiment stuff that didn't work. The previous code was me trying to sort the issue using a select.
Anyway this was the original code:
Code:
'ruleType' => array
(
'label' => &$lang['ruleType'],
'exclude' => true,
'filter' => false,
'inputType' => 'text',
'eval' => array('tl_class'=>'w50', 'readonly'=>true, 'doNotSave'=>true, 'disabled'=>'disabled'),
'load_callback' => array(
array('tl_AWQueue','ruleTypeValue')
)
),
So that is, depending what value is set on the field via load_callback changes the palette structure. For extra reference this is what ruleTypeValue contains:
Code:
public function ruleTypeValue($value, $dc)
{
$objRule = $this->Database->prepare('SELECT `type` FROM `tl_AWRule`, `tl_AWQueue` WHERE `tl_AWQueue`.`rule` = `tl_AWRule`.`id` AND `tl_AWQueue`.`id`=?')
->execute($dc->id);
return $objRule->type;
}
So it picks the string value from another table depending on a relationship with the one being referenced in the DCA.
I would guess that this approach won't work due to the palettes being finalised when load_callback has been called and might require onload_callback to be used for the table.
EDIT:
My suspicions were correct by doing it this way:
For config/onload_callback:
Code:
public function populateSubpalettes($dc)
{
$objRule = $this->Database->prepare('SELECT `type` FROM `tl_AWRule`, `tl_AWQueue` WHERE `tl_AWQueue`.`rule` = `tl_AWRule`.`id` AND `tl_AWQueue`.`id`=?')
->execute($dc->id);
if(array_key_exists('ruleType'.$objRule->type,$GLOBALS['TL_DCA']['tl_AWQueue']['subpalettes']))
{
foreach($GLOBALS['TL_DCA']['tl_AWQueue']['palettes'] as $palette=>$fields)
{
$GLOBALS['TL_DCA']['tl_AWQueue']['palettes'][$palette] =
str_replace('ruleType','ruleType,'.$GLOBALS['TL_DCA']['tl_AWQueue']['subpalettes']['ruleType'.$objRule->type],
$GLOBALS['TL_DCA']['tl_AWQueue']['palettes'][$palette]);
}
}
}
Which for any subpalettes it will pick up just like accordian in tl_content:
Code:
'subpalettes' => array
(
'ruleTypeAWFTest' => 'field1'
),
Any better suggestions are certainly welcome.
Bookmarks