Dynamically add fields to sub-panel on editiviewdefs.php

Hi All,

I am trying to create non-db fields for a custom module from the Account Module.  I want this fields to be dynamically created so that if anything changes on Account Module, new fields can also be brought to my custom module after rebuild.  In my custom/Extension/modules/customModule/Vardefs/customfields.php  I have:

foreach ($dictionary['Account']['fields'] as $fieldKey => $fieldProp) {
    $fieldProp['source'] = 'non-db';
    $fieldProp['type'] = 'bool';
    $fieldProp['label'] = 'LBL_GANDALF_ACCOUNT_' . strtoupper($fieldKey);
    $fieldProp['name'] = "account__". $fieldKey;
    $dictionary['GDLF_Gandalf_Table']['fields']["account__". $fieldKey] = $fieldProp;
}

I would also like to dynamically declare the fields in my editviewdefs.php.  Hoping to do something like 

foreach ($dictionary['Account']['fields'] as $fieldKey => $fieldProp) {
    $fieldProp['label'] = 'LBL_GANDALF_ACCOUNT_' . strtoupper($fieldKey);
    $fieldProp['name'] = "account__". $fieldKey;
    $customFields[]= $fieldProp;
}

And pass that array to a custom  panel declared in edtiviewdefs.php

'lbl_editview_panel1' => 
array (
  0 =>
  array (
    0 => $customFields
  ),
),

$dictionary[] comes empty is there another way to access the fields from a module form within the editiviewdefs.php?

Thanks in advance.

  • Finally did it this way for anyone wondering:

    //Fetch a beach for Account
    $account = BeanFactory::getBean('Accounts');
    //Array of keys to not display in Gandalf Table
    $filteredKeys=['id', 'deleted'];
    //Store each of the available fields from Account into array to custom fields in Gandalf Table
    foreach ((array_keys($account->field_defs)) as $key) {
        //Filter out certain keys from array.
        if (!in_array($key, $filteredKeys)) {
            $fieldProp['source'] = 'non-db';
            $fieldProp['type'] = 'bool';
            $fieldProp['label'] = 'LBL_GANDALF_ACCOUNT_' . strtoupper($key);
            $fieldProp['name'] = "account__". $key;
            $dictionary['GDLF_Gandalf_Table']['fields']["account__". $key] = $fieldProp;
        }
    }

    Thanks.