function global_filter_set_parameter in Views Global Filter 7
Same name and namespace in other branches
- 8 global_filter.storage.inc \global_filter_set_parameter()
Set a name/value pair on the filter by the key $key.
Special cases: o global_filter_set_parameter(NULL, NULL, NULL) simply returns all filter parameters keyed by filter key first and parameter name second. o global_filter_set_parameter($filter_key, NULL, NULL) deletes the filter
Parameters
int $key: a positive integer denoting the filter key
string $name: name of parameter to set, use NULL to delete the filter
mixed $value: the value
bool $reset: whether to reset the cache
Return value
array array of parameters
3 calls to global_filter_set_parameter()
- global_filter_block_info in ./
global_filter.blocks.inc - Implements hook_block_info().
- global_filter_block_save in ./
global_filter.blocks.inc - Implements hook_block_save().
- global_filter_get_parameter in ./
global_filter.storage.inc - Returns parameter value of the specified filter or all parameters if omitted.
File
Code
function global_filter_set_parameter($key, $name, $value, $reset = FALSE) {
// For multiple get's during the same request cache the values. The cache
// lives in this function as it needs to be updated with every set operation.
$parameters =& drupal_static(__FUNCTION__, NULL, $reset);
if (!isset($parameters)) {
$parameters = variable_get(GLOBAL_FILTER_DB_VAR, array());
$legacy_parameters_set = variable_get('global_filter_legacy_parameters_set', FALSE);
for ($j = 1; $j <= GLOBAL_FILTER_MAX_NUM_FILTERS; $j++) {
if (empty($parameters[$j]['name'])) {
if (!$legacy_parameters_set) {
if (_global_filter_load_legacy_parameters($j, $parameters[$j])) {
drupal_set_message(t('Global Filter settings from 7.x-1.8 version or older were successfully loaded and saved in the new format. Filters in the old format were kept also. If you want to revert to the older version of this module AND keep the old settings do NOT uninstall this module. Just copy the old version over the top of this new one.'), 'warning', FALSE);
// Now that parameters have been set, we'll never get here again...
}
variable_set('global_filter_legacy_parameters_set', TRUE);
}
else {
unset($parameters[$j]);
continue;
}
}
if (empty($parameters[$j]['block'])) {
$parameters[$j]['block'] = GLOBAL_FILTER_BLOCK_ID_PREFIX . $j;
}
// Set remaining parameters to empty string to avoid NULLs.
foreach (_global_filter_get_all_parameter_names() as $parameter_name) {
if (!isset($parameters[$j][$parameter_name])) {
$parameters[$j][$parameter_name] = '';
}
}
}
}
if (isset($key)) {
// Update cache and its db backup.
if (isset($name)) {
$parameters[$key][$name] = $value;
}
else {
// Delete this filter.
unset($parameters[$key]);
}
}
if (isset($key) || isset($legacy_parameters_set) && $legacy_parameters_set === FALSE) {
variable_set(GLOBAL_FILTER_DB_VAR, $parameters);
}
return $parameters;
}