panels_allowed_layouts Class Reference
[Panels Main API Functions]

List of all members.


Detailed Description

Class definition for the allowed layouts governing structure.

This class is designed to handle panels allowed layouts data from start to finish, and sees action at two times:

To call the settings form, instantiate this class - or, if your client module's needs are heavy-duty, extend this class and instantiate your subclass - assign values to any relevant desired members, and call panels_allowed_layouts::set_allowed(). See the documentation on that method for a sample implementation.

Note that when unserializing saved tokens of this class, you must run panels_load_include('common') before unserializing in order to ensure that the object is properly loaded.

Client modules extending this class should implement a save() method and use it for their custom data storage routine. You'll need to rewrite other class methods if you choose to go another route.

See also:
panels_edit_layout()

_panels_edit_layout()

Definition at line 45 of file common.inc.


Public Member Functions

 api_save ()
 list_layouts ()
 panels_allowed_layouts ($start_allowed=TRUE)
 set_allowed ($title= 'Panels:Allowed Layouts')
 sync_with_available ()

Public Attributes

 $allow_new = TRUE
 $allowed_layout_settings = array()
 $form_state
 $module_name = NULL

Member Function Documentation

panels_allowed_layouts::api_save (  ) 

Use panels_allowed_layouts::module_name to generate a variable for variable_set(), in which a serialized version of $this will be stored.

Does nothing if panels_allowed_layouts::module_name is not set.

IMPORTANT NOTE: if you use variable_get() in a custom client module save() method, you MUST wrap $this in serialize(), then unserialize() what you get from variable_get(). Failure to do so will result in an incomplete object. The following code will work:

  $allowed_layouts = unserialize(variable_get('your_variable_name', serialize(''));

If you don't serialize the second parameter of variable_get() and the variable name you provide can't be found, an E_STRICT warning will be generated for trying to unserialize an entity that has not been serialized.

Definition at line 197 of file common.inc.

00197                       {
00198     if (!is_null($this->module_name)) {
00199       variable_set($this->module_name . "_allowed_layouts", serialize($this));
00200     }
00201   }

panels_allowed_layouts::list_layouts (  ) 

Snag a list of the current layouts for internal use.

Data is not saved in a class member in order to ensure that it's fresh.

Returns:
array $layouts An indexed array of the system names for all currently available layouts.

Definition at line 212 of file common.inc.

References panels_get_layouts(), and panels_load_include().

Referenced by panels_allowed_layouts(), and sync_with_available().

00212                           {
00213     static $layouts = array();
00214     if (empty($layouts)) {
00215       panels_load_include('plugins');
00216       $layouts = array_keys(panels_get_layouts());
00217     }
00218     return $layouts;
00219   }

Here is the call graph for this function:

Here is the caller graph for this function:

panels_allowed_layouts::panels_allowed_layouts ( start_allowed = TRUE  ) 

Constructor function; loads the $allowed_layout_settings array with initial values according to $start_allowed

Parameters:
bool $start_allowed $start_allowed determines whether all available layouts will be marked as allowed or not allowed on the initial call to panels_allowed_layouts::set_allowed()

Definition at line 93 of file common.inc.

References list_layouts().

00093                                                          {
00094     // TODO would be nice if there was a way to just fetch the names easily
00095     foreach ($this->list_layouts() as $layout_name) {
00096       $this->allowed_layout_settings[$layout_name] = $start_allowed ? 1 : 0;
00097     }
00098   }

Here is the call graph for this function:

panels_allowed_layouts::set_allowed ( title = 'Panels: Allowed Layouts'  ) 

Manage panels_common_set_allowed_layouts(), the FAPI code for selecting allowed layouts.

MAKE SURE to set panels_allowed_layouts::allow_new before calling this method. If you want the panels API to handle saving these allowed layout settings, panels_allowed_layouts::module_name must also be set.

Below is a sample implementation; refer to the rest of the class documentation to understand all the specific pieces. Values that are intended to be replaced are wrapped with <>.


  function docdemo_allowed_layouts() {
    panels_load_include('common');
    if (!is_a($allowed_layouts = unserialize(variable_get('panels_common_allowed_layouts', serialize(''))), 'panels_allowed_layouts')) {
     $allowed_layouts = new panels_allowed_layouts();
      $allowed_layouts->allow_new = TRUE;
      $allowed_layouts->module_name = '<client_module_name>';
    }
    $result = $allowed_layouts->set_allowed('<Desired client module form title>');
    if (in_array($allowed_layouts->form_state, array('failed-validate', 'render'))) {
     return $result;
    }
    elseif ($allowed_layouts->form_state == 'submit') {
      drupal_goto('</path/to/desired/redirect>');
    }
  }

If $allowed_layouts->form_state == 'failed-validate' || 'render', then you'll need to return $result as it contains the structured form HTML generated by drupal_render_form() and is ready to be passed through index.php's call to theme('page', ...).

However, if $allowed_layouts->form_state == 'submit', then the form has been submitted and we should react. It's really up to your client module how you handle the rest; panels_allowed_layouts::save() (or panels_allowed_layouts::api_save(), if that's the route you're going) will have already been called, so if those methods handle your save routine, then all there is left to do is handle redirects, if you want. The current implementation of the allowed layouts form currently never redirects, so it's up to you to control where the user ends up next.

Parameters:
string $title Used to set the title of the allowed layouts form. If no value is given, defaults to 'Panels: Allowed Layouts'.
Returns:
mixed $result
  • On the first passthrough when the form is being rendered, $result is the form's structured HTML, ready to be pushed to the screen with a call to theme('page', ...).
  • A successful second passthrough indicates a successful submit, and $result === panels_allowed_layouts::allowed_layout_settings. Returning it is simply for convenience.

Definition at line 148 of file common.inc.

References sync_with_available().

00148                                        : Allowed Layouts') {
00149     $this->sync_with_available();
00150     $form_id = 'panels_common_set_allowed_layouts';
00151     $form = drupal_retrieve_form($form_id, $this, $title);
00152 
00153     if ($result = drupal_process_form($form_id, $form)) {
00154       // successful submit
00155       $this->form_state = 'submit';
00156       return $result;
00157     }
00158     $this->form_state = isset($_POST['op']) ? 'failed-validate' : 'render';
00159     $result = drupal_render_form($form_id, $form);
00160     return $result;
00161   }

Here is the call graph for this function:

panels_allowed_layouts::sync_with_available (  ) 

Checks for newly-added layouts and deleted layouts. If any are found, updates panels_allowed_layouts::allowed_layout_settings; new additions are made according to panels_allowed_layouts::allow_new, while deletions are unset().

Note that any changes made by this function are not saved in any permanent location.

Definition at line 169 of file common.inc.

References list_layouts().

Referenced by set_allowed().

00169                                  {
00170     $layouts = $this->list_layouts();
00171     foreach (array_diff($layouts, array_keys($this->allowed_layout_settings)) as $new_layout) {
00172       $this->allowed_layout_settings[$new_layout] = $this->allow_new ? 1 : 0;
00173     }
00174     foreach (array_diff(array_keys($this->allowed_layout_settings), $layouts) as $deleted_layout) {
00175       unset($this->allowed_layout_settings[$deleted_layout]);
00176     }
00177   }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

panels_allowed_layouts::$allow_new = TRUE

Specifies whether newly-added layouts (as in, new .inc files) should be automatically allowed (TRUE) or disallowed (FALSE) for $this. Defaults to TRUE, which is more permissive but less of an administrative hassle if/when you add new layouts. Note that this parameter will be derived from $allowed_layouts if a value is passed in.

Definition at line 53 of file common.inc.

panels_allowed_layouts::$allowed_layout_settings = array()

An associative array of all available layouts, keyed by layout name (as defined in the corresponding layout plugin definition), with value = 1 if the layout is allowed, and value = 0 if the layout is not allowed. Calling array_filter(panels_allowed_layouts::$allowed_layout_settings) will return an associative array containing only the allowed layouts, and wrapping that in array_keys() will return an indexed version of that array.

Definition at line 75 of file common.inc.

panels_allowed_layouts::$form_state

Hack-imitation of D6's $form_state. Used by the panels_common_set_allowed_types() form to indicate whether the returned value is in its 'render', 'failed-validate', or 'submit' stage.

Definition at line 82 of file common.inc.

panels_allowed_layouts::$module_name = NULL

Optional member. If provided, the Panels API will generate a drupal variable using variable_set($module_name . 'allowed_layouts', serialize($this)), thereby handling the storage of this object entirely within the Panels API. This object will be called and rebuilt by panels_edit_layout() if the same $module_name string is passed in for the $allowed_types parameter.
This is primarily intended for convenience - client modules doing heavy-duty implementations of the Panels API will probably want to create their own storage method.

See also:
panels_edit_layout()

Definition at line 65 of file common.inc.


The documentation for this class was generated from the following file:

Generated on Thu Jul 29 05:00:19 2010 for Panels 2 by  doxygen 1.5.6