You are here

function social_tagging_form_views_exposed_form_alter in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  2. 8 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  3. 8.3 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  4. 8.4 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  5. 8.5 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  6. 8.6 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  7. 8.7 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  8. 8.8 modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  9. 10.3.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  10. 10.0.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  11. 10.1.x modules/social_features/social_tagging/social_tagging.module \social_tagging_form_views_exposed_form_alter()
  12. 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 346
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',
  ];

  // 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'] = $tag_service
          ->getChildren($tid);
      }
    }
  }
  else {

    // Remove main items and just insert child options.
    $form['tag']['#options'] = [];
    foreach ($tag_service
      ->getCategories() as $tid => $label) {
      if (!empty($options = $tag_service
        ->getChildren($tid))) {
        $form['tag']['#options'][$label] = $options;
      }
    }
  }
}