function global_filter_set_on_session in Views Global Filter 8
Same name and namespace in other branches
- 7 global_filter.storage.inc \global_filter_set_on_session()
Sets the filter of the supplied name to the supplied value.
Parameters
string $name: eg 'field_country', must not be empty
mixed $value: to be set to filter of $name
Return value
bool TRUE if $value was set, FALSE if it wasn't
7 calls to global_filter_set_on_session()
- global_filter_action_set_filter in ./
global_filter.rules.inc - The action function for the 'global_filter_action_set_filter'.
- global_filter_clear_filters in ./
global_filter.module - Set all or the supplied global filters back to their global defaults.
- global_filter_get_view_next_value in ./
global_filter.module - In the supplied view return the successor to the supplied reference value.
- global_filter_init in ./
global_filter.module - Implements hook_init().
- global_filter_set_form_on_session in ./
global_filter.widgets.inc - Stashes the selected global filter value(s) in the user's session.
File
- ./
global_filter.storage.inc, line 181 - global_filter.storage.inc
Code
function global_filter_set_on_session($name, $value) {
// Provide hook_global_filter_value_alter(), so $value can be altered by
// other modules.
drupal_alter('global_filter_value', $name, $value);
if (empty($name)) {
drupal_set_message(t('Global Filter: filter name empty. Cannot set value.'), 'warning');
return FALSE;
}
if (is_array($value)) {
// For e.g. hierarchical select.
$value = global_filter_array_flatten($value);
if (empty($value)) {
$value = '';
}
}
// Gets and caches all filters.
$prev_value = global_filter_get_session_value($name);
if ($prev_value == $value) {
global_filter_debug(t('Global Filter %name: no change in value. No need to set.', array(
'%name' => $name,
)));
return FALSE;
}
// May return '' or NULL.
$filters = global_filter_get_session_value();
if (empty($filters)) {
$filters = array();
}
// Update the selected filter with the new value.
$filters[$name] = $value;
$prev_value = !isset($prev_value) || $prev_value == '' ? t('all') : (is_array($prev_value) ? implode('+', $prev_value) : print_r($prev_value, TRUE));
$value = !isset($value) || $value == '' ? t('all') : (is_array($value) ? implode('+', $value) : print_r($value, TRUE));
global_filter_debug(t('Global Filter %name: changing from %prev_value to %value', array(
'%name' => $name,
'%prev_value' => $prev_value,
'%value' => $value,
)));
if ($name != 'view_autocycle' && global_filter_get_module_parameter('mutex_mode', FALSE)) {
global_filter_debug(t('Global Filter mutex mode is on, so setting other filters back to their global defaults...'));
foreach (global_filter_get_parameter(NULL) as $filter) {
$nm = $filter['name'];
if ($nm && $nm != $name && $nm != 'view_autocycle') {
$filters[$nm] = global_filter_get_global_default($nm);
global_filter_debug(t('Global Filter %name: mutex reset to global default: "%value"', array(
'%name' => $nm,
'%value' => is_array($filters[$nm]) ? implode('+', $filters[$nm]) : $filters[$nm],
)));
}
}
}
// Set all updated filters.
session_cache_set('global_filter', $filters);
// Invoke the Rules event: "A Views Global Filter has been set".
if (module_exists('rules')) {
rules_invoke_event('global_filter_set_filter_done', $name, $value);
}
return TRUE;
}