did; if (!$did) { $display->did = $did = 'new'; } // Load the display being edited from cache, if possible. if (!empty($_POST) && is_object($cache = panels_edit_cache_get($did))) { $display = $cache->display; } else { $cache = panels_edit_cache_get_default($display, $content_types, $title); } // Get a renderer. $renderer = panels_get_renderer_handler('editor', $display); $renderer->cache = $cache; $output = $renderer->edit(); if (is_object($output) && $destination) { return panels_goto($destination); } return $output; } /** * Form definition for the panels display editor * * No validation function is necessary, as all 'validation' is handled * either in the lead-up to form rendering (through the selection of * specified content types) or by the validation functions specific to * the ajax modals & content types. * * @ingroup forms * @see panels_edit_display_submit() */ function panels_edit_display_form($form, &$form_state) { $display = &$form_state['display']; $renderer = &$form_state['renderer']; // Make sure there is a valid cache key. $cache_key = isset($display->cache_key) ? $display->cache_key : $display->did; $display->cache_key = $cache_key; // Annoyingly, theme doesn't have access to form_state so we have to do this. $form['#display'] = $display; // The flexible layout maker wants to be able to edit a display without // actually editing a display, so we provide this 'setting' to allow // that to go away. if (empty($form_state['no display settings'])) { $links = $renderer->get_display_links(); } else { $renderer->no_edit_links = TRUE; $links = ''; } $form['hide']['display-settings'] = array( '#markup' => $links, ); $form += panels_edit_display_settings_form($form, $form_state); $form['panel'] = array('#tree' => TRUE); $form['panel']['pane'] = array('#tree' => TRUE); $form['display'] = array( '#markup' => $renderer->render(), ); foreach ($renderer->plugins['layout']['regions'] as $region_id => $title) { // Make sure we at least have an empty array for all possible locations. if (!isset($display->panels[$region_id])) { $display->panels[$region_id] = array(); } $form['panel']['pane'][$region_id] = array( // Use 'hidden' instead of 'value' so the js can access it. '#type' => 'hidden', '#default_value' => implode(',', (array) $display->panels[$region_id]), ); } if (empty($form_state['no buttons'])) { $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#id' => 'panels-dnd-save', '#submit' => array('panels_edit_display_form_submit'), '#save-display' => TRUE, ); $form['buttons']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); } // Build up the preview portion of the form, if necessary. if (empty($form_state['no preview'])) { $form['preview'] = array( '#tree' => TRUE, '#prefix' => '

' . t('Live preview') . '

' . '
', '#suffix' => '
', ); ctools_context_replace_form($form['preview'], $display->context); $form['preview']['button'] = array( '#type' => 'submit', '#value' => t('Preview'), '#attributes' => array('class' => array('use-ajax-submit')), '#id' => 'panels-live-preview-button', '#submit' => array('panels_edit_display_form_submit', 'panels_edit_display_form_preview'), ); } return $form; } /** * Handle form validation of the display content editor. */ function panels_edit_display_form_validate($form, &$form_state) { panels_edit_display_settings_form_validate($form, $form_state); } /** * Handle form submission of the display content editor. * * This reads the location of the various panes from the form, which will * have been modified from the ajax, rearranges them and then saves * the display. */ function panels_edit_display_form_submit($form, &$form_state) { $display = &$form_state['display']; $old_content = $display->content; $display->content = array(); if (!empty($form_state['values']['panel']['pane'])) { foreach ($form_state['values']['panel']['pane'] as $region_id => $panes) { $display->panels[$region_id] = array(); if ($panes) { $pids = explode(',', $panes); // need to filter the array, b/c passing it in a hidden field can generate trash foreach (array_filter($pids) as $pid) { if ($old_content[$pid]) { $display->panels[$region_id][] = $pid; $old_content[$pid]->panel = $region_id; $display->content[$pid] = $old_content[$pid]; // If the panel has region locking, make sure that the region // the panel is in is applicable. This can happen if the panel // was moved and then the lock changed and the server didn't // know. if (!empty($old_content[$pid]->locks) && $old_content[$pid]->locks['type'] == 'regions') { $old_content[$pid]->locks['regions'][$region_id] = $region_id; } } } } } } panels_edit_display_settings_form_submit($form, $form_state); } /** * Submission of the preview button. Render the preview and put it into * the preview widget area. */ function panels_edit_display_form_preview(&$form, &$form_state) { $display = &$form_state['display']; ctools_include('ajax'); $display->context = ctools_context_replace_placeholders($display->context, $form_state['values']['preview']); $display->skip_cache = TRUE; $output = panels_render_display($display); // Add any extra CSS that some layouts may have added specifically for this. if (!empty($display->add_css)) { $output = "\n" . $output; } $commands = array(); $commands[] = array( 'command' => 'panel_preview', 'output' => $output, ); print ajax_render($commands); ajax_footer(); exit; } /** * Form for display settings. */ function panels_edit_display_settings_form($form, &$form_state) { $display = &$form_state['display']; $layout = panels_get_layout($display->layout); $form_state['layout'] = $layout; ctools_include('dependent'); if ($form_state['display_title']) { $form['display_title'] = array ( '#tree' => TRUE, ); $form['display_title']['hide_title'] = array( '#type' => 'select', '#title' => t('Title type'), '#default_value' => (int) $display->hide_title, '#options' => array( PANELS_TITLE_NONE => t('No title'), PANELS_TITLE_FIXED => t('Manually set'), PANELS_TITLE_PANE => t('From pane'), ), ); $form['display_title']['title'] = array( '#type' => 'textfield', '#default_value' => $display->title, '#title' => t('Title'), '#description' => t('The title of this panel. If left blank, a default title may be used. If you want the title actually to be blank, change the "Title type" dropdown from "Manually Set" to "No Title".'), '#process' => array('ctools_dependent_process'), '#dependency' => array('edit-display-title-hide-title' => array(PANELS_TITLE_FIXED)), '#maxlength' => 255, ); if (!empty($display->context)) { $form['display_title']['title']['#description'] .= ' ' . t('You may use substitutions in this title.'); // We have to create a manual fieldset because fieldsets do not support IDs. // Use 'hidden' instead of 'markup' so that the process will run. // Add js for collapsible fieldsets manually // drupal_add_js('misc/form.js'); // drupal_add_js('misc/collapse.js'); // $form['display_title']['contexts_prefix'] = array( // '#type' => 'hidden', // '#id' => 'edit-display-substitutions', // '#prefix' => '
', // ); } } // TODO doc the ability to do this as part of the API if (!empty($layout['settings form']) && function_exists($layout['settings form'])) { $form['layout_settings'] = $layout['settings form']($display, $layout, $display->layout_settings); } $form['layout_settings']['#tree'] = TRUE; return $form; } /** * Validate the layout settings form. */ function panels_edit_display_settings_form_validate($form, &$form_state) { if ($function = panels_plugin_get_function('layout', $form_state['layout'], 'settings validate')) { $function($form_state['values']['layout_settings'], $form['layout_settings'], $form_state['display'], $form_state['layout'], $form_state['display']->layout_settings); } } /** * Store changes from the layout settings form. */ function panels_edit_display_settings_form_submit($form, &$form_state) { $display = &$form_state['display']; if ($function = panels_plugin_get_function('layout', $form_state['layout'], 'settings submit')) { $function($form_state['values']['layout_settings'], $display, $form_state['layout'], $display->layout_settings); } // Since not all layouts have layout settings, check here in case of notices. if (isset($form_state['values']['layout_settings'])) { $display->layout_settings = $form_state['values']['layout_settings']; } if (isset($form_state['values']['display_title']['title'])) { $display->title = $form_state['values']['display_title']['title']; $display->hide_title = $form_state['values']['display_title']['hide_title']; } }