boxes_box.inc in Boxes 6
File
plugins/boxes_box.inc
View source
<?php
abstract class boxes_box {
static $boxes;
public $delta;
public $title;
public $description;
public $options;
public $plugin_key;
public $new;
public $export_type;
public static function load($delta, $reset = false) {
if (!isset(self::$boxes[$delta]) || $reset) {
ctools_include('export');
$box = ctools_export_load_object('box', 'names', array(
$delta,
));
if (!empty($box) && ($values = array_pop($box))) {
self::$boxes[$delta] = self::factory($values->plugin_key, $values);
self::$boxes[$delta]->new = false;
}
}
return isset(self::$boxes[$delta]) ? self::$boxes[$delta] : NULL;
}
public static function factory($plugin_key, $values) {
ctools_include('plugins');
if ($class = ctools_plugin_load_class('boxes', 'plugins', $plugin_key, 'handler')) {
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;
}
protected function __construct() {
$this->new = TRUE;
$this->options = $this
->options_defaults();
}
public static function reset() {
ctools_include('export');
ctools_export_load_object_reset('box');
self::$boxes = array();
}
public function save() {
if (empty($this->delta)) {
throw new Exception(t('Cannot save box without a specified delta.'));
}
self::reset();
$existing = boxes_load($this->delta);
if ($existing && $existing->export_type & EXPORT_IN_DATABASE) {
drupal_write_record('box', $this, array(
'delta',
));
}
else {
drupal_write_record('box', $this);
}
$this->new = FALSE;
self::reset();
module_exists('context') ? context_invalidate_cache() : NULL;
}
public function delete() {
self::reset();
unset(self::$boxes[$this->delta]);
db_query("DELETE FROM {box} WHERE delta = '%s'", $this->delta);
module_exists('context') ? context_invalidate_cache() : NULL;
}
public abstract function options_defaults();
public abstract function options_form();
public abstract function render();
}
Classes
Name |
Description |
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. |