function mefibs_bef_mefibs_elements_alter in MEFIBS - More exposed forms in blocks 7
Same name and namespace in other branches
- 8 modules/mefibs_bef/mefibs_bef.module \mefibs_bef_mefibs_elements_alter()
Implements hook_mefibs_elements_alter().
File
- modules/
mefibs_bef/ mefibs_bef.module, line 12 - Primarily Drupal hooks and global API functions to add support for the Better Exposed Filters module.
Code
function mefibs_bef_mefibs_elements_alter(&$elements, $context) {
$view = $context['view'];
$display_id = $view->current_display;
$options = $view->display[$display_id]->handler
->get_option('exposed_form');
$mefibs = $view->display_handler
->get_option('mefibs');
if ($options['type'] != 'better_exposed_filters') {
return;
}
$bef_settings = $options['options']['bef'];
// Add needed javascript support for sliders and select links.
drupal_add_js(drupal_get_path('module', 'mefibs_bef') . '/mefibs_bef.js');
// Check if secondary exposed form is present.
$use_secondary = isset($bef_settings['general']['allow_secondary']) && $bef_settings['general']['allow_secondary'];
if ($use_secondary && in_array($context['block_id'], $mefibs[$display_id]['secondary_form_block'])) {
// Make sure it's getting rendered.
if ($context['type'] == 'hide_items') {
$elements[] = 'secondary';
}
// Also make sure we know how to handle it.
if ($context['type'] == 'expected_items') {
// BEF stores the filter names, not the identifiers! So we have to check for ourselves.
$exposed_items = mefibs_get_exposed_items($view);
foreach ($exposed_items['filter'] as $filter_identifier => $filter_name) {
if (!isset($bef_settings[$filter_name]['more_options']['is_secondary'])) {
continue;
}
$is_secondary = $bef_settings[$filter_name]['more_options']['is_secondary'];
if ($is_secondary) {
// It's a filter in the secondary exposed form.
$elements['filter'][$filter_identifier] = $filter_name;
}
}
}
}
if (!isset($bef_settings['sort']['advanced']['combine'])) {
return;
}
if (!$bef_settings['sort']['advanced']['combine']) {
return;
}
$sort_block = isset($mefibs[$display_id]['sort_block']) && in_array($context['block_id'], $mefibs[$display_id]['sort_block']);
if ($context['type'] == 'expected_items' && $sort_block) {
$elements['sort'][] = 'sort_bef_combine';
}
if ($context['type'] == 'hide_items' && $sort_block) {
$elements[] = 'sort_bef_combine';
}
}