Allows to populate drop-down, radio- or checkbox list fields, which have been added with
shop:onExtendCustomGroupForm event.
Usually you do not need to use this event for fields which represent
data relations. But if you want a standard
field (corresponding an integer-typed database column, for example), to be rendered as a drop-down list, you should
handle this event.
The event handler should accept 2 parameters - the field name and a current field value. If the current
field value is -1, the handler should return an array containing a list of options. If the current
field value is not -1, the handler should return a string (label), corresponding the value.
public function subscribeEvents()
{
Backend::$events->addEvent('shop:onExtendCustomGroupModel', $this, 'extend_custom_group_model');
Backend::$events->addEvent('shop:onExtendCustomGroupForm', $this, 'extend_custom_group_form');
Backend::$events->addEvent('shop:onGetCustomGroupFieldOptions', $this, 'get_custom_group_options');
}
public function extend_custom_group_model($custom_group, $context)
{
$custom_group->define_column('x_gender', 'Gender');
}
public function extend_custom_group_form($custom_group, $context)
{
$custom_group->add_form_field('x_gender')->tab('Group')->renderAs(frm_dropdown);
}
public function get_custom_group_options($field_name, $current_value)
{
if ($field_name == 'x_gender')
{
$options = array('male'=>'Male', 'female'=>'Female', 'unisex'=>'Unisex');
if ($current_value == -1)
return $options;
if (array_key_exists($current_value, $options))
return $options[$current_value];
}
}