1 views_ui.admin.inc | views_ui_edit_form_submit_clone_display_as_type($form, &$form_state) |
Submit handler to clone a display as another display type.
File
- core/
modules/ views_ui/ views_ui.admin.inc, line 1380 - Admin page callbacks for the Views UI module.
Code
function views_ui_edit_form_submit_clone_display_as_type($form, &$form_state) {
$view = $form_state['view'];
$display_id = $form_state['display_id'];
// Create the new display.
$parents = $form_state['triggering_element']['#parents'];
$display_type = array_pop($parents);
$new_display_id = $view->add_display($display_type);
// Let the display title be generated by the add_display method and set the
// right display plugin, but keep the rest of the from from the original
// display.
$display_clone = clone $view->display[$display_id];
unset($display_clone->display_title);
unset($display_clone->display_plugin);
$new_display_array = backdrop_array_merge_deep((array) $view->display[$new_display_id], (array) $display_clone);
foreach ($new_display_array as $key => $value) {
$view->display[$new_display_id]->{$key} = $value;
}
$view->display[$new_display_id]->id = $new_display_id;
// By setting the current display, the "changed" marker will appear on the new
// display.
$view->current_display = $new_display_id;
views_ui_cache_set($view);
// Redirect to the new display's edit page.
$form_state['redirect'] = 'admin/structure/views/view/' . $view->name . '/configure/' . $new_display_id;
}