You are here

function panels_ajax_flexible_edit_reuse in Panels 6.3

Same name and namespace in other branches
  1. 7.3 plugins/layouts/flexible/flexible.inc \panels_ajax_flexible_edit_reuse()

AJAX form to bring up the "reuse" modal.

1 string reference to 'panels_ajax_flexible_edit_reuse'
flexible.inc in plugins/layouts/flexible/flexible.inc

File

plugins/layouts/flexible/flexible.inc, line 1664

Code

function panels_ajax_flexible_edit_reuse($handler) {
  $settings =& $handler->display->layout_settings;
  panels_flexible_convert_settings($settings, $handler->plugins['layout']);
  $form_state = array(
    'display' => &$handler->display,
    'settings' => &$settings,
    'ajax' => TRUE,
    'title' => t('Save this layout for reuse'),
  );
  $output = ctools_modal_form_wrapper('panels_flexible_reuse_form', $form_state);
  if (empty($output)) {

    // Create the new layout.
    ctools_include('export');
    $layout = ctools_export_crud_new('panels_layout');
    $layout->plugin = 'flexible';
    $layout->name = $form_state['values']['name'];
    $layout->admin_title = $form_state['values']['admin_title'];
    $layout->admin_description = $form_state['values']['admin_description'];
    $layout->category = $form_state['values']['category'];
    $layout->settings = $handler->display->layout_settings;

    // Save it.
    ctools_export_crud_save('panels_layout', $layout);
    if (empty($form_state['values']['keep'])) {

      // Set the actual layout_settings to now use the newly minted layout:
      $handler->display->layout = 'flexible:' . $layout->name;
      $handler->display->layout_settings = array();

      // Save our new state.
      panels_edit_cache_set($handler->cache);
    }

    // Dismiss the modal.
    $output[] = ctools_modal_command_dismiss();
  }
  $handler->commands = $output;
}