Last active
September 8, 2015 09:29
-
-
Save leanderlindahl/041d27b4abcd413f1fd5 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
function popolo_custom_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){ | |
/** | |
* Apply the form_alter to a specific form #id | |
* the form #id can be found through inspecting the markup | |
*/ | |
if($form['#id'] == 'views-exposed-form-filter-articles-page-1') { | |
/** | |
* Include a js and css, which was defined in popolo_custom.libraries.yml | |
*/ | |
$form['#attached']['library'][] = 'popolo_custom/popolo_custom.enable'; | |
$form['#attached']['library'][] = 'popolo_custom/popolo_custom.forms'; | |
/** | |
* Extract the options from the Views Exposed Filter <select>-list | |
*/ | |
$links = $form['field_tags_target_id']['#options']; | |
/** | |
* Iterate over the options ($links) to build an array ($pop_array) of links | |
*/ | |
$i = 0; // Initiate counter/index | |
$pop_array = array(); | |
foreach ($links as $tid => $term_name) { | |
if ($tid == 'All') { | |
$pop_array[$i]['#markup'] = '<span class="filter-tab"><a href="" class="active" id="' .$tid . '">' . $term_name . '</a></span>'; | |
} | |
else { | |
$pop_array[$i]['#markup'] = '<span class="filter-tab"><a href="" id="' .$tid . '">' . $term_name . '</a></span>'; | |
} | |
$i++; // Increase counter/index | |
} | |
/** | |
* Create the item-list the form should render | |
*/ | |
$form['links'] = [ | |
'#theme' => 'item_list', | |
'#items' => $pop_array, | |
'#attributes' => array('class' => array('pop-list')), | |
]; | |
} | |
else { | |
//nothing... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment