Index: trunk/core/kernel/db/db_event_handler.php =================================================================== diff -u -r3983 -r4000 --- trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 3983) +++ trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 4000) @@ -1562,6 +1562,37 @@ } } } + + /** + * Dynamically fills customdata config + * + * @param kEvent $event + */ + function OnCreateCustomFields(&$event) + { + $main_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + + // 1. get custom field information + $item_type = $this->Application->getUnitOption($main_prefix, 'ItemType'); + $sql = 'SELECT FieldName, CustomFieldId + FROM '.TABLE_PREFIX.'CustomField + WHERE Type = '.$item_type; + $custom_fields = $this->Conn->GetCol($sql, 'CustomFieldId'); + + // 2. create fields (for customdata item) + $fields = $this->Application->getUnitOption($event->Prefix, 'Fields', Array()); + $field_options = Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'not_null' => 1, 'db_type' => 'text', 'default' => ''); + foreach ($custom_fields as $custom_id => $custom_name) { + $fields['cust_'.$custom_name] = $field_options; + } + $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); + + + /*// 3. create virtual & calculated fields (for main item) + $calculated_fields = $this->Application->getUnitOption($main_prefix.'.', 'CalculatedFields', Array()); + $virtual_fields = $this->Application->getUnitOption($main_prefix, 'VirtualFields', Array());*/ + + } }