You are here

public static function boxes_box::factory in Boxes 6

Same name and namespace in other branches
  1. 7 plugins/boxes_box.inc \boxes_box::factory()

Instantiate, populate and return a box object.

Parameters

$plugin_key:

$values: An array with at least a plugin_key key identifying the plugin class to use for instantiating this box.

2 calls to boxes_box::factory()
boxes_box::load in plugins/boxes_box.inc
Load existing box by its unique identifier $delta.
boxes_factory in ./boxes.module
Instantiate box object.

File

plugins/boxes_box.inc, line 43

Class

boxes_box
Abstract base class defining a box. A boxes content plugin provides a form of options for configuring content and renders content for display.

Code

public static function factory($plugin_key, $values) {
  ctools_include('plugins');
  if ($class = ctools_plugin_load_class('boxes', 'plugins', $plugin_key, 'handler')) {

    // While we actually prefer to get objects, we need to allow for either,
    // so we convert it all to arrays.
    if (is_object($values)) {
      $values = (array) $values;
    }
    $box = new $class();
    $box->plugin_key = $plugin_key;
    foreach ($box as $key => $value) {
      if (isset($values[$key])) {
        $box->{$key} = $values[$key];
      }
    }
    foreach ($box
      ->options_defaults() as $key => $value) {
      if (isset($values[$key])) {
        $box->options[$key] = $values[$key];
      }
    }
    return $box;
  }
  return false;
}