Panels Main API Functions


Detailed Description

These functions comprise the main Panels API. Module developers interested in providing data to Panels, or using Panels as the organization/presentation layer for their module, should familiarize themselves with these functions first and foremost.


Classes

class  panels_allowed_layouts
class  panels_display

Functions

 panels_delete_display ($display)
 panels_edit ($display, $destination=NULL, $content_types=NULL)
 panels_edit_layout ($display, $finish, $destination=NULL, $allowed_layouts=NULL)
 panels_edit_layout_settings ($display, $finish, $destination=NULL, $title=FALSE)
 panels_export_display ($display, $prefix= '')
 panels_export_export ()
 panels_export_export_form_submit ($form_id, $form_values)
 panels_load_display ($did)
 panels_new_display ()
 panels_save_display (&$display)


Function Documentation

panels_delete_display ( display  ) 

Delete a display.

Definition at line 808 of file panels.module.

Referenced by panels_mini_delete(), panels_mini_uninstall(), panels_node_delete(), panels_page_context_form_submit(), and panels_page_delete().

00808                                          {
00809   if (is_object($display)) {
00810     $did = $display->did;
00811   }
00812   else {
00813     $did = $display;
00814   }
00815   db_query("DELETE FROM {panels_display} WHERE did = %d", $did);
00816   db_query("DELETE FROM {panels_pane} WHERE did = %d", $did);
00817 }

Here is the caller graph for this function:

panels_edit ( display,
destination = NULL,
content_types = NULL 
)

Main API entry point to edit a panel display.

Sample implementations utiltizing the the complex $destination behavior can be found in panels_page_edit_content() and, in a separate contrib module, OG Blueprints (http://drupal.org/project/og_blueprints), og_blueprints_blueprint_edit().

Parameters:
object $display instanceof panels_display
A fully loaded panels $display object, as returned from panels_load_display(). Merely passing a did is NOT sufficient.
Note that 'fully loaded' means the $display must already be loaded with any contexts the caller wishes to have set for the display.
mixed $destination
The redirect destination that the user should be taken to on form submission or cancellation. With panels_edit, $destination has complex effects on the return values of panels_edit() once the form has been submitted. See the explanation of the return value below to understand the different types of values returned by panels_edit() at different stages of FAPI. Under most circumstances, simply passing in drupal_get_destination() is all that's necessary.
array $content_types
An associative array of allowed content types, typically as returned from panels_common_get_allowed_types(). Note that context partially governs available content types, so you will want to create any relevant contexts using panels_create_context() or panels_create_context_empty() to make sure all the appropriate content types are available.
Returns:
Because the functions called by panels_edit() invoke the form API, this function returns different values depending on the stage of form submission we're at. In Drupal 5, the phase of form submission is indicated by the contents of $_POST['op']. Here's what you'll get at different stages:
  1. If !$_POST['op']: then we're on on the initial passthrough and the form is being rendered, so it's the $form itself that's being returned. Because negative margins, a common CSS technique, bork the display editor's ajax drag-and-drop, it's important that the $output be printed, not returned. Use this syntax in the caller function:
    print theme('page', panels_edit($display, $destination, $content_types), FALSE);
  2. If $_POST['op'] == t('Cancel'): form submission has been cancelled. If empty($destination) == FALSE, then there is no return value and the panels API takes care of redirecting to $destination. If empty($destination) == TRUE, then there's still no return value, but the caller function has to take care of form redirection.
  3. If $_POST['op'] == ('Save'): the form has been submitted successfully and has run through panels_edit_display_submit(). $output depends on the value of $destination:
    • If empty($destination) == TRUE: $output contains the modified $display object, and no redirection will occur. This option is useful if the caller needs to perform additional operations on or with the modified $display before the page request is complete. Using hook_form_alter() to add an additional submit handler is typically the preferred method for something like this, but there are certain use cases where that is infeasible and $destination = NULL should be used instead. If this method is employed, the caller will need to handle form redirection. Note that having $_REQUEST['destination'] set, whether via drupal_get_destination() or some other method, will NOT interfere with this functionality; consequently, you can use drupal_get_destination() to safely store your desired redirect in the caller function, then simply use drupal_goto() once panels_edit() has done its business.
    • If empty($destination) == FALSE: the form will redirect to the URL string given in $destination and NO value will be returned.

Definition at line 440 of file panels.module.

References _panels_edit(), and panels_load_include().

Referenced by panels_mini_edit_content(), panels_node_edit_content(), and panels_page_edit_content().

00440                                                                            {
00441   panels_load_include('display_edit');
00442   panels_load_include('plugins');
00443   return _panels_edit($display, $destination, $content_types);
00444 }

Here is the call graph for this function:

Here is the caller graph for this function:

panels_edit_layout ( display,
finish,
destination = NULL,
allowed_layouts = NULL 
)

API entry point for selecting a layout for a given display.

Layout selection is nothing more than a list of radio items encompassing the available layouts for this display, as defined by .inc files in the panels/layouts subdirectory. The only real complexity occurs when a user attempts to change the layout of a display that has some content in it.

Parameters:
object $display instanceof panels_display
A fully loaded panels $display object, as returned from panels_load_display(). Merely passing a did is NOT sufficient.
string $finish A string that will be used for the text of the form submission button. If no value is provided, then the form submission button will default to t('Save').
mixed $destination Basic usage is a string containing the URL that the form should redirect to upon submission. For a discussion of advanced usages, see panels_edit().
mixed $allowed_layouts Allowed layouts has three different behaviors that depend on which of three value types are passed in by the caller: #- if $allowed_layouts instanceof panels_allowed_layouts (includes subclasses): the most complex use of the API. The caller is passing in a loaded panels_allowed_layouts object that the client module previously created and stored somewhere using a custom storage mechanism. #- if is_string($allowed_layouts): the string will be used in a call to variable_get() which will call the $allowed_layouts . '_allowed_layouts' var. If the data was stored properly in the system var, the $allowed_layouts object will be unserialized and recreated.
See also:
panels_common_set_allowed_layouts() #- if is_null($allowed_layouts): the default behavior, which also provides backwards compatibility for implementations of the Panels2 API written before beta4. In this case, a dummy panels_allowed_layouts object is created which does not restrict any layouts. Subsequent behavior is indistinguishable from pre-beta4 behavior.
Returns:
Can return nothing, or a modified $display object, or a redirection string; return values for the panels_edit* family of functions are quite complex. See panels_edit() for detailed discussion.
See also:
panels_edit()

Definition at line 486 of file panels.module.

References _panels_edit_layout(), and panels_load_include().

Referenced by panels_mini_edit_layout(), panels_node_edit_layout(), and panels_page_edit_layout().

00486                                                                                              {
00487   panels_load_include('display_edit');
00488   panels_load_include('plugins');
00489   return _panels_edit_layout($display, $finish, $destination, $allowed_layouts);
00490 }

Here is the call graph for this function:

Here is the caller graph for this function:

panels_edit_layout_settings ( display,
finish,
destination = NULL,
title = FALSE 
)

API entry point for configuring the layout settings for a given display.

For all layouts except Flexible, the layout settings form allows the user to select styles, as defined by .inc files in the panels/styles subdirectory, for the panels in their display. For the Flexible layout, the layout settings form allows the user to provide dimensions for their flexible layout in addition to applying styles to panels.

TODO and at some point, individual panes should be stylable as well as whole panels.

Parameters:
object $display instanceof panels_display
A fully loaded panels $display object, as returned from panels_load_display(). Merely passing a did is NOT sufficient.
string $finish A string that will be used for the text of (one of) the form submission button(s). Note that panels will NOT wrap $finish in t() for you, so your caller should make sure to do so.
The submit behavior of the form is primarily governed by the value of $destination (see below), but is secondarily governed by $finish as follows:
  1. If $finish != t('Save'), then two submit buttons will be present: one with the button text t('Save'), and the other with the button text $finish. .
    • Clicking the 'Save' button will save any changes on the form to the $display object and keep the user on the same editing page.
    • Clicking the $finish button will also save the $display object, but the user will be redirected to the URL specified in $destination.
  2. If $finish == t('Save'), then there is only one button, still called t('Save'), but it mimics the behavior of the $finish button above by redirecting the user away from the form.
mixed $destination Basic usage is a string containing the URL that the form should redirect to upon submission. For a discussion of advanced usages that rely on NULL values for $destination, see the panels_edit() documentation.
mixed $title The $title variable has three modes of operation:
  1. If $title == FALSE (the default), then no widget will appear on the panels_edit_layout_settings form allowing the user to select a title, and other means for setting page titles will take precedent. If no other means are used to provide a title, then the title will be hidden when rendering the $display.
  2. If $title == TRUE, then two widgets will appear on the panels_edit_layout_settings form allowing the user to input a title specific to this $display, as well as a checkbox enabling the user to disable page titles entirely for this $display object.
  3. If $title == (string), then the behavior is very similar to mode 2, but the widget description on the title textfield will indicate that the $title string will be used as the default page title if none is provided on this form. When utilizing this option, note that the panels API can only provide the data for these values; you must implement the appropriate conditionals to make it true.
Returns:
Can return nothing, or a modified $display object, or a redirection string; return values for the panels_edit* family of functions are quite complex. See panels_edit() for detailed discussion.
See also:
panels_edit()

Definition at line 542 of file panels.module.

References _panels_edit_layout_settings(), and panels_load_include().

Referenced by panels_mini_edit_layout_settings(), panels_node_edit_layout_settings(), and panels_page_edit_layout_settings().

00542                                                                                              {
00543   panels_load_include('display_edit');
00544   panels_load_include('plugins');
00545   return _panels_edit_layout_settings($display, $finish, $destination, $title);
00546 }

Here is the call graph for this function:

Here is the caller graph for this function:

panels_export_display ( display,
prefix = '' 
)

Exports the provided display into portable code.

This function is primarily intended as a mechanism for cloning displays. It generates an exact replica (in code) of the provided $display, with the exception that it replaces all ids (dids and pids) with 'new-*' values. Only once panels_save_display() is called on the code version of $display will the exported display written to the database and permanently saved.

See also:
panels_page_export() or _panels_page_fetch_display() for sample implementations.
Parameters:
object $display instanceof panels_display
This export function does no loading of additional data about the provided display. Consequently, the caller should make sure that all the desired data has been loaded into the $display before calling this function.
string $prefix A string prefix that is prepended to each line of exported code. This is primarily used for prepending a double space when exporting so that the code indents and lines up nicely.
Returns:
string $output The passed-in $display expressed as code, ready to be imported. Import by running eval($output) in the caller function; doing so will create a new $display variable with all the exported values. Note that if you have already defined a $display variable in the same scope as where you eval(), your existing $display variable WILL be overwritten.

Definition at line 846 of file panels.module.

References panels_export_pane(), and panels_var_export().

Referenced by panels_mini_export(), panels_page_export(), and panels_page_save_display().

00846                                                        {
00847   $output = '';
00848   $output .= $prefix . '$display = new panels_display()' . ";\n";
00849   $output .= $prefix . '$display->did = \'new\'' . ";\n";
00850   $fields = array('layout', 'layout_settings', 'panel_settings', 'cache', 'title', 'hide_title');
00851   foreach ($fields as $field) {
00852     if (isset($display->$field)) {
00853       $output .= $prefix . '$display->' . $field . ' = ' . panels_var_export($display->$field, $prefix) . ";\n";
00854     }
00855   }
00856 
00857   $output .= $prefix . '$display->content = array()' . ";\n";
00858   $output .= $prefix . '$display->panels = array()' . ";\n";
00859   $panels = array();
00860 
00861   if (!empty($display->content)) {
00862     $pid_counter = 0;
00863     $region_counters = array();
00864     foreach ($display->content as $pane) {
00865       $pane->pid = 'new-' . ++$pid_counter;
00866       $output .= panels_export_pane($pane, $prefix . '  ');
00867       $output .= "$prefix  " . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
00868       if (!isset($region_counters[$pane->panel])) {
00869         $region_counters[$pane->panel] = 0;
00870       }
00871       $output .= "$prefix  " . '$display->panels[\'' . $pane->panel . '\'][' . $region_counters[$pane->panel]++ .'] = \'' . $pane->pid . "';\n";
00872     }
00873   }
00874   return $output;
00875 }

Here is the call graph for this function:

Here is the caller graph for this function:

panels_export_export (  ) 

Page callback to export panels in bulk.

Definition at line 48 of file panels_export.module.

00048                                 {
00049   $exportables = array();
00050   foreach (module_implements('panels_exportables') as $module) {
00051     $function = $module . '_panels_exportables';
00052     $exportables[$module] = $function('list');
00053   }
00054   if ($exportables) {
00055     $form_id = 'panels_export_export_form';
00056     $form    = drupal_retrieve_form($form_id, $exportables);
00057     $output  = drupal_process_form($form_id, $form);
00058     if (!$output) {
00059       $output = drupal_render_form($form_id, $form);
00060     }
00061     return $output;
00062   }
00063   else {
00064     return t('There are no panels to be exported at this time.');
00065   }
00066 }

panels_export_export_form_submit ( form_id,
form_values 
)

Handle submission of the panels batch exporting form.

Definition at line 126 of file panels_export.module.

00126                                                                   {
00127   $code = '';
00128   if (empty($form_values['name'])) {
00129     $form_values['name'] = 'foo';
00130   }
00131 
00132   foreach ($form_values['modules'] as $module => $panels) {
00133     $panels = array_filter($panels);
00134     if ($panels) {
00135       $code .= module_invoke($module, 'panels_exportables', 'export', $panels, $form_values['name']) . "\n\n";
00136     }
00137   }
00138 
00139   $lines = substr_count($code, "\n");
00140   $element = array(
00141     '#type' => 'textarea',
00142     '#id' => 'export-textarea',
00143     '#name' => 'export-textarea',
00144     '#attributes' => array(),
00145     '#rows' => min($lines, 150),
00146     '#value' => $code,
00147     '#parents' => array(),
00148   );
00149 
00150   return theme('textarea', $element);
00151 }

panels_load_display ( did  ) 

Load a single display.

Parameters:
int $did The display id (did) of the display to be loaded.
Returns:
object $display instanceof panels_display
Returns a partially-loaded panels_display object. $display objects returned from from this function have only the following data:
  • $display->did (the display id)
  • $display->name (the 'name' of the display, where applicable - it often isn't)
  • $display->layout (a string with the system name of the display's layout)
  • $display->panel_settings (custom layout style settings contained in an associative array; NULL if none)
  • $display->layout_settings (panel size and configuration settings for Flexible layouts; NULL if none)
  • $display->css_id (the special css_id that has been assigned to this display, if any; NULL if none)
  • $display->content (an array of pane objects, keyed by pane id (pid))
  • $display->panels (an associative array of panel regions, each an indexed array of pids in the order they appear in that region)
  • $display->cache (any relevant data from panels_simple_cache)
  • $display->args
  • $display->incoming_content
While all of these members are defined, $display->context is NEVER defined in the returned $display; it must be set using one of the panels_context_create() functions.

Definition at line 729 of file panels.module.

References panels_load_displays().

Referenced by panels_mini_export(), panels_mini_load(), panels_node_edit_content(), panels_node_edit_layout(), panels_node_edit_layout_settings(), panels_node_view(), panels_page_edit(), panels_page_export(), panels_page_fetch_display_from_info(), panels_page_fetch_primary_display(), and panels_page_load().

00729                                    {
00730   $displays = panels_load_displays(array($did));
00731   if (!empty($displays)) {
00732     return array_shift($displays);
00733   }
00734 }

Here is the call graph for this function:

Here is the caller graph for this function:

panels_new_display (  ) 

Creates a new display, setting the ID to our magic new id.

Definition at line 638 of file panels.module.

Referenced by panels_mini_add_page(), panels_node_insert(), and panels_page_add_page().

00638                               {
00639   $display = new panels_display();
00640   $display->did = 'new';
00641   return $display;
00642 }

Here is the caller graph for this function:

panels_save_display ( &$  display  ) 

Save a display object.

Note a new $display only receives a real did once it is run through this function. Until then, it uses a string placeholder, 'new', in place of a real did. The same applies to all new panes (whether on a new $display or not); in addition, panes have sequential numbers appended, of the form 'new-1', 'new-2', etc.

Parameters:
object $display instanceof panels_display
The display object to be saved. Passed by reference so the caller need not use the return value for any reason except convenience.
Returns:
object $display instanceof panels_display

Definition at line 752 of file panels.module.

References panels_clear_cached_content(), panels_get_content_type(), and panels_load_include().

Referenced by _panels_page_insert(), _panels_page_update(), panels_choose_layout_submit(), panels_edit_display_submit(), panels_edit_layout_settings_form_submit(), panels_mini_save(), panels_node_insert(), and panels_page_save_import().

00752                                         {
00753   if ($display->did && $display->did != 'new') {
00754     if (empty($display->cache)) {
00755       $display->cache = array();
00756     }
00757     db_query("UPDATE {panels_display} SET layout = '%s', layout_settings = '%s', panel_settings = '%s', cache = '%s', title = '%s', hide_title = %d WHERE did = %d", $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title, $display->did);
00758     db_query("DELETE FROM {panels_pane} WHERE did = %d", $display->did);
00759   }
00760   else {
00761     $display->did = db_next_id("{panels_display}_did");
00762     db_query("INSERT INTO {panels_display} (did, layout, layout_settings, panel_settings, cache, title, hide_title) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $display->did, $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title);
00763   }
00764 
00765   // update all the panes
00766   panels_load_include('plugins');
00767   foreach ((array) $display->panels as $id => $panes) {
00768     $position = 0;
00769     $new_panes = array();
00770     foreach ((array) $panes as $pid) {
00771       $pane = $display->content[$pid];
00772       $pane->position = $position++;
00773       if (!is_numeric($pid)) {
00774         unset($display->content[$pid]);
00775         $pane->pid = db_next_id("{panels_pane}_pid");
00776       }
00777       if (empty($pane->cache)) {
00778         $pane->cache = array();
00779       }
00780 
00781       $type = panels_get_content_type($pane->type);
00782       $access = isset($pane->access) ? implode(', ', $pane->access) : '';
00783       $visibility = $type['visibility serialize'] ? serialize($pane->visibility) : $pane->visibility;
00784       // doin it this way for readability
00785       $f = 'pid, did, panel, type, subtype, configuration, cache, shown, access, visibility, position';
00786       $q = "%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d";
00787       $pane->shown = isset($pane->shown) ? $pane->shown : TRUE;
00788       $v = array($pane->pid, $display->did, $pane->panel, $pane->type, $pane->subtype, serialize($pane->configuration), serialize($pane->cache), $pane->shown, $access, $visibility, $pane->position);
00789       db_query("INSERT INTO {panels_pane} ($f) VALUES ($q)", $v);
00790       // and put it back so our pids and positions can be used
00791       $display->content[$pane->pid] = $pane;
00792       $new_panes[] = $pane->pid;
00793     }
00794     $display->panels[$id] = $new_panes;
00795   }
00796 
00797   // Clear any cached content for this display.
00798   panels_clear_cached_content($display);
00799 
00800   // to be nice, even tho we have a reference.
00801   return $display;
00802 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Feb 5 05:00:26 2012 for Panels 2 by  doxygen 1.5.6