Hello. Could you give me your advice in this scenario.
I need to create a series of fields (7) in a large number of modules. Doing it one by one using studio seems like too much work because I also have to add the fields to the editing and creation views in each module.
I’m looking for ideas to smooth this out.
I thought I could create the fields programmatically. Try something like this
<?php
global $app;
$modules = ['module1', 'module2', '...']; // $GLOBALS['moduleList']?
foreach ($modules as $module) {
$bean = BeanFactory::getBean($module);
$fields = $bean->getFieldDefinitions();
// if field `field_1_c` does not exist in $fields then
if () {
$dictionary[$module]['fields']['field_1_c'] = [
'name' => 'field_1_c',
'vname' => 'LBL_FIELD_1_C',
'type' => 'enum',
'required' => true,
'default' => '',
'options' => 'cstm_some_list',
'audited' => true,
'importable' => true
];
}
// if field `field_2_c` does not exist in $fields then
if () {
$dictionary[$module]['fields']['field_2_c'] = [
'name' => 'field_2_c',
'vname' => 'LBL_FIELD_2_C',
'type' => 'text',
'default' => '',
'required' => false,
'importable' => 'true',
'reportable' => true,
'audited' => false,
];
}
}
Place it for example in public/legacy/custom/Extension/modules/Contacts/Ext/Vardefs/custom_fields.php
And every time I Quick Repair and Rebuild add the fields if they don’t exist in each module
Another option I thought could be to create the fields in a module and replicate them by changing the name of the module in the fields_meta_data table
For example
+---------------------------+-------------------+---------------------+--------+-------+-------------+-------+---+--------+-------------+-------------------+-------+-------+----------+---------------+----------+----------+----+----+----+----+
|id |name |vname |comments|help |custom_module|type |len|required|default_value|date_modified |deleted|audited|massupdate|duplicate_merge|reportable|importable|ext1|ext2|ext3|ext4|
+---------------------------+-------------------+---------------------+--------+-------+-------------+-------+---+--------+-------------+-------------------+-------+-------+----------+---------------+----------+----------+----+----+----+----+
|Accountsjjwg_maps_address_c|jjwg_maps_address_c|LBL_JJWG_MAPS_ADDRESS|Address |Address|Accounts |varchar|255|0 |null |2019-02-18 12:06:37|0 |1 |0 |0 |1 |true |null| | | |
+---------------------------+-------------------+---------------------+--------+-------+-------------+-------+---+--------+-------------+-------------------+-------+-------+----------+---------------+----------+----------+----+----+----+----+
Could you suggest me a solution?
Regarding adding the fields in the creation and editing views of each module, will there be any shortcut?
Greetings and thanks