Allows to add new columns or relations to the Option Matrix model.
Adding new columns and relations is only required if you want to extend Option Matrix with an images field.
This event should be used with the
event. In the event handler
you can define new relations and columns. The following example adds Extra Images column to the Option Matrix:
public function subscribeEvents()
{
Backend::$events->add_event('shop:onExtendOptionMatrix', $this, 'extend_option_matrix');
Backend::$events->add_event('shop:onExtendOptionMatrixRecordModel', $this, 'extend_option_matrix_model');
}
public function extend_option_matrix($model, $context)
{
$result = array(
'x_extra_images'=>array(
'title'=>'Extra image',
'type'=>'popup',
'editor_class'=>'Db_GridImagesEditor',
'images_field'=>'x_extra_images',
'width'=>100,
'column_group'=>'Custom')
);
if ($context != 'grid')
$model->add_form_field('x_extra_images')->renderAs(frm_file_attachments)->renderFilesAs('image_list');
return $result;
}
public function extend_option_matrix_model($model, $context)
{
$front_end = Db_ActiveRecord::$execution_context == 'front-end';
$model->add_relation('has_many', 'x_extra_images', array(
'class_name'=>'Db_File',
'foreign_key'=>'master_object_id',
'conditions'=>"master_object_class='Shop_OptionMatrixRecord' and field='x_extra_images'",
'order'=>'sort_order, id',
'delete' => true)
);
$model->define_multi_relation_column('x_extra_images', 'x_extra_images', 'Extra images', $front_end ? null : '@name')->invisible();
}