How to change Views field settings programmatically? 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-&gt;display-&gt;display_options['fields']['field_gallery_natural_images']['id'] = 'field_gallery_natural_images';
$handler-&gt;display-&gt;display_options['fields']['field_gallery_natural_images']['table'] = 'field_data_field_gallery_natural_images';
$handler-&gt;display-&gt;display_options['fields']['field_gallery_natural_images']['field'] = 'field_gallery_natural_images';
$handler-&gt;display-&gt;display_options['fields']['field_gallery_natural_images']['click_sort_column'] = 'fid';
$handler-&gt;display-&gt;display_options['fields']['field_gallery_natural_images']['type'] = 'colorbox';
$handler-&gt;display-&gt;display_options['fields']['field_gallery_natural_images']['settings'] = array(
  'colorbox_node_style' =&gt; '',
  'colorbox_image_style' =&gt; '',
  'colorbox_gallery' =&gt; 'post',
  'colorbox_gallery_custom' =&gt; '',
  'colorbox_caption' =&gt; 'auto',
  'colorbox_caption_custom' =&gt; '',
  'display_empty' =&gt; '',
  'custom_text' =&gt; '',
  'empty_callback' =&gt; 'mymodule_empty_fields_no_data',
);


I would like to change the "Image style" of the Colorbox formatter somehow like this:

$handler-&gt;display-&gt;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']-&gt;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.
UPDATED:

You can use this code snippet to change a view without views_alter:

$view = views_get_view($view_name, TRUE);
$view-&gt;display['default']-&gt;display_options['fields']['field_gallery_natural_images']['settings']['colorbox_node_style'] = 'thumbnail';
views_save_view($view);


Change default display ID if you want to use display other than the default.



If you have exported the view to code using hook_views_default_views() or the Features module, there is a hook to alter the views programmatically:

/**
 * Alter default views defined by other modules.
 *
 * This hook is called right before all default views are cached to the
 * database. It takes a keyed array of views by reference.
 *
 * Example usage to add a field to a view:
 * @code
 *   $handler =&amp; $view-&gt;display['DISPLAY_ID']-&gt;handler;
 *   // Add the user name field to the view.
 *   $handler-&gt;display-&gt;display_options['fields']['name']['id'] = 'name';
 *   $handler-&gt;display-&gt;display_options['fields']['name']['table'] = 'users';
 *   $handler-&gt;display-&gt;display_options['fields']['name']['field'] = 'name';
 *   $handler-&gt;display-&gt;display_options['fields']['name']['label'] = 'Author';
 *   $handler-&gt;display-&gt;display_options['fields']['name']['link_to_user'] = 1;
 * @endcode
 */
function hook_views_default_views_alter(&amp;$views) {
  if (isset($views['taxonomy_term'])) {
    $views['taxonomy_term']-&gt;display['default']-&gt;display_options['title'] = 'Categories';
  }
}


For example:

/**
 * Implements hook_views_default_views_alter()
 */
function MYMODULE_views_default_views_alter(&amp;$views) {
  if (isset($views['VIEW_NAME'])) {
    $views['VIEW_NAME']-&gt;display['default']-&gt;display_options['fields']['field_gallery_natural_images']['settings']['colorbox_node_style'] = 'thumbnail';
  }
}


Remember to clear the cache and do revert of the view to apply changes.