function social_tagging_form_views_exposed_form_alter in Open Social 8.9
Same name and namespace in other branches
- 8 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.2 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.3 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.4 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.5 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.6 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.7 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 8.8 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 10.3.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 10.0.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 10.1.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
- 10.2.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
Implements hook_form_FORM_ID_alter().
File
- modules/
social_features/ social_tagging/ social_tagging.module, line 392 - Contains social_tagging.module.
Code
function social_tagging_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_ids = [
'views-exposed-form-search-content-page-no-value',
'views-exposed-form-search-content-page',
'views-exposed-form-search-groups-page-no-value',
'views-exposed-form-search-groups-page',
'views-exposed-form-latest-topics-page-latest-topics',
'views-exposed-form-upcoming-events-page-community-events',
'views-exposed-form-topics-page-profile',
'views-exposed-form-events-events-overview',
'views-exposed-form-group-topics-page-group-topics',
'views-exposed-form-group-events-page-group-events',
'views-exposed-form-newest-groups-page-all-groups',
];
// Must be either one of these form_ids.
if (!in_array($form['#id'], $form_ids)) {
return;
}
/** @var \Drupal\social_tagging\SocialTaggingService $tag_service */
$tag_service = \Drupal::service('social_tagging.tag_service');
if (!($tag_service
->active() && $tag_service
->hasContent())) {
return;
}
if ($tag_service
->allowSplit()) {
foreach ($tag_service
->getCategories() as $tid => $label) {
$label = social_tagging_to_machine_name($label);
if (isset($form[$label])) {
$form[$label]['#options'] = [];
$form[$label]['#options'][''] = t('- Any -');
$form[$label]['#options'] += $tag_service
->getChildren($tid);
$form[$label]['#type'] = 'select2';
$form[$label]['#size'] = NULL;
/** @var \Symfony\Component\HttpFoundation\ParameterBag $query */
$query = \Drupal::request()->query;
if ($query
->has($label)) {
$form[$label]['#value'] = $query
->get($label);
}
}
}
}
else {
// Remove main items and just insert child options.
$form['tag']['#options'] = [];
$form['tag']['#options'][''] = t('- Any -');
$form['tag']['#type'] = 'select2';
$form['tag']['#size'] = NULL;
/** @var \Symfony\Component\HttpFoundation\ParameterBag $query */
$query = \Drupal::request()->query;
if ($query
->has('tag')) {
$form['tag']['#value'] = $query
->get('tag');
}
foreach ($tag_service
->getCategories() as $tid => $label) {
if (!empty($options = $tag_service
->getChildren($tid))) {
$form['tag']['#options'][$label] = $options;
}
}
}
}