I would like to change some field settings in a given view created with Views programmatically.
For example, I would like to change the "Formatter" and "Image style" settings of an Image field. This is what the settings of this field look like when I export this view:
/* Field: Taxonomy term: Natural images */
$handler->display->display_options['fields']['field_gallery_natural_images']['id'] = 'field_gallery_natural_images';
$handler->display->display_options['fields']['field_gallery_natural_images']['table'] = 'field_data_field_gallery_natural_images';
$handler->display->display_options['fields']['field_gallery_natural_images']['field'] = 'field_gallery_natural_images';
$handler->display->display_options['fields']['field_gallery_natural_images']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_gallery_natural_images']['type'] = 'colorbox';
$handler->display->display_options['fields']['field_gallery_natural_images']['settings'] = array(
'colorbox_node_style' => '',
'colorbox_image_style' => '',
'colorbox_gallery' => 'post',
'colorbox_gallery_custom' => '',
'colorbox_caption' => 'auto',
'colorbox_caption_custom' => '',
'display_empty' => '',
'custom_text' => '',
'empty_callback' => 'mymodule_empty_fields_no_data',
);
I would like to change the "Image style" of the Colorbox formatter somehow like this:
$handler->display->display_options['fields']['field_gallery_natural_images']['settings']['colorbox_node_style'] = 'thumbnail';
and save that. How should I do that?
Like here:
EDIT 1.
Maybe I should use views_save_view()
:
http://api.drupal.org/api/views/views.module/function/views_save_view/7
It saves a view - so maybe I should query the whole view, change that, and use this function. But how exactly?
EDIT 2.
I found in views/includes/admin.inc
that the given view gets saved like this: $form_state['view']->save();
in views_ui_edit_view_form_submit()
.
I already know how to change "Image style" of an Image field in a given view mode programmatically (as on "Manage display" tab after clicking the gear), but now I would be happy if I could do something similar with a given view.