LemonStand Documentation

shop:onGetExtraOptionFieldOptions event

The shop:onGetExtraOptionFieldOptions event allows to populate drop-down, radio- or checkbox list fields, which you added with the shop:onExtendExtraOptionForm event, with custom options. 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 in your module.

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, corresponding the value.

Event handler example:

public function subscribeEvents()
{
  Backend::$events->addEvent('shop:onExtendExtraOptionModel', $this, 'extend_extra_model');
  Backend::$events->addEvent('shop:onExtendExtraOptionForm', $this, 'extend_extra_form');
  Backend::$events->addEvent('shop:onGetExtraOptionFieldOptions', $this, 'get_extra_field_options');
}

public function extend_extra_model($model)
{
  $model->define_column('x_custom_field', 'Custom field');
}

public function extend_extra_form($model, $context)
{
  $model->add_form_field('x_custom_field', 'Color')->renderAs(frm_dropdown)->tab('Option');
}

public function get_extra_field_options($field, $current_key_value=-1)
{
  if ($field_name == 'x_custom_field')
  {
    $options = array(
      0 => 'Option 1',
      1 => 'Option 2'
    );
 
    if ($current_key_value == -1)
      return $options;
 
    if (array_key_exists($current_key_value, $options))
      return $options[$current_key_value];
  }
}

Next: cms:onExtendTemplateForm event
Previous: shop:onExtendExtraOptionForm event
Return to Handling LemonStand events