You are here

function social_search_alter_content_exposed_filter_block in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_search/social_search.module \social_search_alter_content_exposed_filter_block()
  2. 8.7 modules/social_features/social_search/social_search.module \social_search_alter_content_exposed_filter_block()
  3. 10.3.x modules/social_features/social_search/social_search.module \social_search_alter_content_exposed_filter_block()
  4. 10.0.x modules/social_features/social_search/social_search.module \social_search_alter_content_exposed_filter_block()
  5. 10.1.x modules/social_features/social_search/social_search.module \social_search_alter_content_exposed_filter_block()
  6. 10.2.x modules/social_features/social_search/social_search.module \social_search_alter_content_exposed_filter_block()

Implements hook_form_FORM_ID_alter().

Makes changes for the filter block on the content search page.

1 call to social_search_alter_content_exposed_filter_block()
social_search_form_views_exposed_form_alter in modules/social_features/social_search/social_search.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_search/social_search.module, line 97
The Social search module.

Code

function social_search_alter_content_exposed_filter_block(&$form, FormStateInterface $form_state, $form_id) {
  if (!empty($form['type'])) {
    $form['type']['#weight'] = '-100';
  }
  if (!empty($form['field_event_date']) && !empty($form['field_event_date_op'])) {
    if (!empty($form['settings'])) {
      $form['settings']['#states'] = [
        'visible' => [
          ':input[name=type]' => [
            'value' => 'event',
          ],
        ],
      ];
      $form['settings']['#weight'] = '-99';
      $form['settings']['#attributes']['class'] = [
        'indent_filter',
      ];
    }
    $form['settings']['field_event_date_op'] = $form['field_event_date_op'];
    $form['settings']['field_event_date'] = $form['field_event_date'];
    unset($form['field_event_date'], $form['field_event_date_op']);
  }
  if (!empty($form['location_details'])) {
    $form['location_details']['#weight'] = '-98';
    $form['location_details']['#attributes']['class'] = [
      'indent_filter',
    ];
  }

  // When combined sorting and filtering is used we make some changes to
  // accommodate theming.
  if (isset($form['sort_bef_combine'])) {

    // Ensure the sort option shows up at the top.
    $form['sort_bef_combine']['#weight'] = -9999;

    // From a UX perspective it doesn't make sense to show the least relevant
    // results first so we remove this sorting option.
    if (isset($form['sort_bef_combine']['#options']['search_api_relevance ASC'])) {
      unset($form['sort_bef_combine']['#options']['search_api_relevance ASC']);
    }

    // We attach custom CSS so that we can properly translate the filter title.
    // This selector should match the value in sort_filter.css of this module.
    // Use a useless variable to trick phpcs from giving us invalid warnings.
    $translated_filter = t('Filter');
    $form['social_search_translated_filter_string'] = [
      '#type' => 'html_tag',
      '#tag' => 'style',
      '#attributes' => [
        'type' => 'text/css',
      ],
      '#value' => "#block-filter .form-item-sort-bef-combine:after { content: '{$translated_filter}'; }",
    ];
  }
}