Last active
May 4, 2018 19:19
-
-
Save init90/2bd9a2092ce5863d54d811366ed95896 to your computer and use it in GitHub Desktop.
Drupal, if views filter without options we remove it from output on hook_form_alter().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isset($form['#id']) && $form['#id'] == 'VIEW_FILTER_ID') { | |
$filters_list = array(); | |
// Get filters names. | |
foreach($form['#info'] as $filter_name => $filter_info) { | |
// Return filter name without 'filter-' prefix. | |
$filters_list[] = substr($filter_name, 7); | |
} | |
foreach($filters_list as $filter) { | |
// If filter without options, we remove it. | |
if (isset($form[$filter]) && empty($form[$filter]['#options'])) { | |
unset($form['#info']["filter-{$filter}"]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment