function ajax_set_layout($layout) { ctools_include('context'); ctools_include('display-layout', 'panels'); $form_state = array('layout' => $layout, 'display' => $this->display, 'finish' => t('Save'), 'no_redirect' => TRUE); // Reset the $_POST['ajax_html_ids'] values to preserve // proper IDs on form elements when they are rebuilt // by the Panels IPE without refreshing the page $_POST['ajax_html_ids'] = array(); $output = drupal_build_form('panels_change_layout', $form_state); $output = drupal_render($output); if (!empty($form_state['executed'])) { if (isset($form_state['back'])) { return $this->ajax_change_layout(); } if (!empty($form_state['clicked_button']['#save-display'])) { // Saved. Save the cache. panels_edit_cache_save($this->cache); $this->display->skip_cache; // Since the layout changed, we have to update these things in the // renderer in order to get the right settings. $layout = panels_get_layout($this->display->layout); $this->plugins['layout'] = $layout; if (!isset($layout['regions'])) { $this->plugins['layout']['regions'] = panels_get_regions($layout, $this->display); } $this->meta_location = 'inline'; $this->commands[] = ajax_command_replace("#panels-ipe-display-{$this->clean_key}", panels_render_display($this->display, $this)); $this->commands[] = ctools_modal_command_dismiss(); return; } } $this->commands[] = ctools_modal_command_display(t('Change layout'), $output); }
/** * Receive and store the display object to be rendered. * * This is a psuedo-constructor that should typically be called immediately * after object construction. * * @param array $plugin * The definition of the renderer plugin. * @param panels_display $display * The panels display object to be rendered. */ function init($plugin, &$display) { $this->plugin = $plugin; $layout = panels_get_layout($display->layout); $this->display =& $display; $this->plugins['layout'] = $layout; if (!isset($layout['panels'])) { $this->plugins['layout']['panels'] = panels_get_regions($layout, $display); } if (empty($this->plugins['layout'])) { watchdog('panels', "Layout: @layout couldn't been found, maybe the theme is disabled.", array('@layout' => $display->layout)); } }
/** * FAPI callback to create the Save/Cancel form for the IPE. */ function panels_ipe_edit_control_form(&$form_state) { $display =& $form_state['display']; // @todo -- this should be unnecessary as we ensure cache_key is set in add_meta() // $display->cache_key = isset($display->cache_key) ? $display->cache_key : $display->did; // Annoyingly, theme doesn't have access to form_state so we have to do this. $form['#display'] = $display; $layout = panels_get_layout($display->layout); $layout_panels = panels_get_regions($layout, $display); $form['panel'] = array('#tree' => TRUE); $form['panel']['pane'] = array('#tree' => TRUE); foreach ($layout_panels as $panel_id => $title) { // Make sure we at least have an empty array for all possible locations. if (!isset($display->panels[$panel_id])) { $display->panels[$panel_id] = array(); } $form['panel']['pane'][$panel_id] = array('#type' => 'hidden', '#default_value' => implode(',', (array) $display->panels[$panel_id])); } $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#id' => 'panels-ipe-save', '#submit' => array('panels_edit_display_form_submit'), '#save-display' => TRUE); $form['buttons']['cancel'] = array('#type' => 'submit', '#value' => t('Cancel'), '#id' => 'panels-ipe-cancel'); return $form; }
function edit_form(&$form, &$form_state) { ctools_include('plugins', 'panels'); // If the plugin is not set, then it should be provided as an argument: if (!isset($form_state['item']->plugin)) { $form_state['item']->plugin = $form_state['function args'][2]; } parent::edit_form($form, $form_state); $form['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#description' => t('What category this layout should appear in. If left blank the category will be "Miscellaneous".'), '#default_value' => $form_state['item']->category); ctools_include('context'); ctools_include('display-edit', 'panels'); ctools_include('content'); // Provide actual layout admin UI here. // Create a display for editing: $cache_key = 'builder-' . $form_state['item']->name; // Load the display being edited from cache, if possible. if (!empty($_POST) && is_object($cache = panels_edit_cache_get($cache_key))) { $display =& $cache->display; } else { $content_types = ctools_content_get_available_types(); panels_cache_clear('display', $cache_key); $cache = new stdClass(); $display = panels_new_display(); $display->did = $form_state['item']->name; $display->layout = $form_state['item']->plugin; $display->layout_settings = $form_state['item']->settings; $display->cache_key = $cache_key; $display->editing_layout = TRUE; $cache->display = $display; $cache->content_types = $content_types; $cache->display_title = FALSE; panels_edit_cache_set($cache); } // Set up lipsum content in all of the existing panel regions: $display->content = array(); $display->panels = array(); $custom = ctools_get_content_type('custom'); $layout = panels_get_layout($display->layout); $regions = panels_get_regions($layout, $display); foreach ($regions as $id => $title) { $pane = panels_new_pane('custom', 'custom'); $pane->pid = $id; $pane->panel = $id; $pane->configuration = ctools_content_get_defaults($custom, 'custom'); $pane->configuration['title'] = 'Lorem Ipsum'; $pane->configuration['body'] = $this->lipsum; $display->content[$id] = $pane; $display->panels[$id] = array($id); } $form_state['display'] =& $display; // Tell the Panels form not to display buttons. $form_state['no buttons'] = TRUE; $form_state['no display settings'] = TRUE; $form_state['cache_key'] = $cache_key; $form_state['content_types'] = $cache->content_types; $form_state['display_title'] = FALSE; $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display); $form_state['renderer']->cache =& $cache; $form = panels_edit_display_form($form, $form_state); // If we leave the standard submit handler, it'll try to reconcile // content from the input, but we've not exposed that to the user. This // makes previews work with the content we forced in. $form['preview']['button']['#submit'] = array('panels_edit_display_form_preview'); }
/** * Configure lock on a pane form. */ function panels_edit_configure_pane_lock_form($form, &$form_state) { ctools_form_include($form_state, 'plugins', 'panels'); form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class'); $display =& $form_state['display']; $pane =& $form_state['pane']; if (empty($pane->locks)) { $pane->locks = array('type' => 'none', 'regions' => array()); } $form['type'] = array('#type' => 'radios', '#title' => t('Lock type'), '#options' => array('none' => t('No lock'), 'immovable' => t('Immovable'), 'regions' => t('Regions')), '#default_value' => $pane->locks['type']); $layout = panels_get_layout($display->layout); $regions = panels_get_regions($layout, $display); $form['regions'] = array('#type' => 'checkboxes', '#title' => t('Regions'), '#options' => $regions, '#description' => t('Select which regions this pane can be moved to.'), '#dependency' => array('radio:type' => array('regions')), '#default_value' => $pane->locks['regions']); $form['#after_build'][] = 'panels_edit_configure_pane_lock_form_after_build'; $form['next'] = array('#type' => 'submit', '#value' => t('Save')); return $form; }
/** * Render all panes in the attached display into their panel regions, then * render those regions. * * @return array $content * An array of rendered panel regions, keyed on the region name. */ function render_regions() { ctools_include('content'); // First, render all the panes into little boxes. We do this here because // some panes request to be rendered after other panes (primarily so they // can do the leftovers of forms). $panes = $first = $normal = $last = array(); foreach ($this->display->content as $pid => $pane) { $pane->shown = !empty($pane->shown); // guarantee this field exists. // If the user can't see this pane, do not render it. if (!$pane->shown || !panels_pane_access($pane, $this->display)) { continue; } $content_type = ctools_get_content_type($pane->type); // If this pane wants to render last, add it to the $last array. We allow // this because some panes need to be rendered after other panes, // primarily so they can do things like the leftovers of forms. if (!empty($content_type['render last'])) { $last[$pid] = $pane; } else { if (!empty($content_type['render first'])) { $first[$pid] = $pane; } else { $normal[$pid] = $pane; } } } foreach ($first + $normal + $last as $pid => $pane) { $panes[$pid] = $this->render_pane($pane); } // Loop through all panels, put all panes that belong to the current panel // in an array, then render the panel. Primarily this ensures that the // panes are in the proper order. $content = array(); foreach ($this->display->panels as $panel_name => $pids) { $panel_panes = array(); foreach ($pids as $pid) { if (!empty($panes[$pid])) { $panel_panes[$pid] = $panes[$pid]; } } $content[$panel_name] = $this->render_region($panel_name, $panel_panes); } // Prevent notices by making sure that all panels at least have an entry: $panels = panels_get_regions($this->plugins['layout'], $this->display); foreach ($panels as $id => $panel) { if (!isset($content[$id])) { $content[$id] = NULL; } } return $content; }