function spaces_presets in Spaces 6.2
Same name and namespace in other branches
- 5.2 spaces.module \spaces_presets()
- 6 spaces.module \spaces_presets()
Gather an array of spaces presets from the DB.
Spaces presets allow for easier space instantiation by the user in the UI. A spaces preset lets you define which features are enabled and diabled and pre-configure settings for a space instance, all of which a user would normally have to take care of in the UI. The result of a spaces_preset is a radio button on the UI that the user can select in order to use a defined preset for the instance of a space they are about to create. Spaces presets can be built in the UI and then exported to code by implementing hook_spaces_presets which should define and return the array exported from the UI on admin/build/space
Parameters
$type: Optional space type to filter results by.
$include_disabled: Optional flag to return all presets, including disabled ones.
$reset: Optional reset flag for clearing the static cache.
Return value
An array of space types where $key => $value corresponds to the space type => space class.
11 calls to spaces_presets()
- spaces_basic_form in ./
spaces_admin.inc - BASIC FORM =========================================================
- spaces_features_export_render in ./
spaces.features.inc - Implementation of hook_spaces_features_export_render().
- spaces_features_form in ./
spaces_admin.inc - FEATURE SETTINGS ===================================================
- spaces_form_presets in ./
spaces.module - Preset options form that can be reused by implementing modules.
- spaces_load in ./
spaces.module - Load a space.
1 string reference to 'spaces_presets'
- spaces_features_api in ./
spaces.module - Implementation of hook_features_api().
File
- ./
spaces.module, line 833
Code
function spaces_presets($type = NULL, $include_disabled = FALSE, $reset = FALSE) {
static $presets;
if (!isset($presets)) {
$presets = array();
$disabled = variable_get('spaces_disabled_presets', array());
// Collect presets provided by modules in code
foreach (module_implements('spaces_presets') as $module) {
$items = module_invoke($module, 'spaces_presets');
foreach ($items as $id => $preset) {
$preset['disabled'] = isset($disabled[$preset['type']][$id]);
$preset['storage'] = SPACES_PRESET_DEFAULT;
$presets[$preset['type']][$id] = $preset;
}
}
// Allow modules to alter presets.
drupal_alter('spaces_presets', $presets);
$result = db_query("SELECT * FROM {spaces_presets}");
while ($row = db_fetch_object($result)) {
$preset = array(
'name' => check_plain($row->name),
'description' => check_plain($row->description),
'type' => check_plain($row->type),
'preset' => unserialize($row->value),
'disabled' => isset($disabled[$row->type][$row->id]),
'storage' => isset($presets[$row->type][$row->id]) ? SPACES_PRESET_OVERRIDDEN : SPACES_PRESET_NORMAL,
);
$presets[$row->type][$row->id] = $preset;
}
}
$return = $presets;
if (!$include_disabled) {
foreach (array_keys($return) as $preset_type) {
foreach ($return[$preset_type] as $id => $preset) {
if ($preset['disabled']) {
unset($return[$preset_type][$id]);
}
}
}
}
if ($type) {
return isset($return[$type]) ? $return[$type] : array();
}
return $return;
}