function spaces_preset_enforce in Spaces 6.2
Same name and namespace in other branches
- 5.2 spaces.module \spaces_preset_enforce()
- 6 spaces.module \spaces_preset_enforce()
Enforces a spaces preset.
5 calls to spaces_preset_enforce()
- spaces_basic_form_submit in ./
spaces_admin.inc - spaces_features_form in ./
spaces_admin.inc - FEATURE SETTINGS ===================================================
- spaces_load in ./
spaces.module - Load a space.
- spaces_preset_form in ./
spaces_admin.inc - Form for adding or editing a spaces preset.
- spaces_save in ./
spaces.module - Saves a space object's feature/setting values.
File
- ./
spaces.module, line 719
Code
function spaces_preset_enforce(&$space, $force = FALSE) {
$presets = spaces_presets($space->type);
if (isset($space->preset) && isset($presets[$space->preset])) {
$preset = $presets[$space->preset]['preset'];
// Enforce features, settings, customizer
$keys = array(
'features',
'settings',
'customizer',
);
foreach ($keys as $key) {
if (isset($preset[$key]) && is_array($preset[$key])) {
// If forced, completely replace any existing settings.
if ($force) {
$space->{$key} = $preset[$key];
}
else {
foreach ($preset[$key] as $k => $v) {
if (!empty($preset['locked'][$key][$k]) || !isset($space->{$key}[$k])) {
$space->{$key}[$k] = $v;
}
}
}
}
}
// Weights are a bit trickier
// Sorting features in a preset according to their weights
if (isset($preset['weights']) && is_array($preset['weights'])) {
// Exclude any weight values that don't correspond to entries in the features array.
$preset['weights'] = array_intersect_key($preset['weights'], $space->features);
// Fill in excessively high weight entries for any features that don't exist in
// the weights array.
$i = 0;
foreach (array_diff_key($space->features, $preset['weights']) as $feature => $value) {
$preset['weights'][$feature] = 1000 + $i;
$i++;
}
// Ensure the keys line up to begin with
ksort($preset['weights']);
ksort($space->features);
array_multisort($preset['weights'], $space->features, SORT_NUMERIC);
}
// Type-specific presets
$space
->preset_enforce($preset);
}
}