social_search.module in Open Social 8
Same filename and directory in other branches
- 8.9 modules/social_features/social_search/social_search.module
- 8.2 modules/social_features/social_search/social_search.module
- 8.3 modules/social_features/social_search/social_search.module
- 8.4 modules/social_features/social_search/social_search.module
- 8.5 modules/social_features/social_search/social_search.module
- 8.6 modules/social_features/social_search/social_search.module
- 8.7 modules/social_features/social_search/social_search.module
- 8.8 modules/social_features/social_search/social_search.module
- 10.3.x modules/social_features/social_search/social_search.module
- 10.0.x modules/social_features/social_search/social_search.module
- 10.1.x modules/social_features/social_search/social_search.module
- 10.2.x modules/social_features/social_search/social_search.module
The Social search module.
File
modules/social_features/social_search/social_search.moduleView source
<?php
/**
* @file
* The Social search module.
*/
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter().
*
* Enhance the Views exposed filter blocks forms.
*/
function social_search_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$filter_forms = [
'views-exposed-form-search-content-page',
'views-exposed-form-search-users-page',
];
if (in_array($form['#id'], $filter_forms)) {
// Set current path as form action, in order to keep search input.
$form['#action'] = \Drupal::service('path.current')
->getPath();
// Always enable the reset button.
$form['actions']['reset']['#access'] = TRUE;
if ($form['#id'] == 'views-exposed-form-search-users-page') {
foreach ($form as &$element) {
if (is_array($element) && isset($element['#type']) && $element['#type'] == 'entity_autocomplete') {
$element['#selection_settings']['hide_id'] = TRUE;
}
}
}
}
}
/**
* Implements hook_block_view_BASE_BLOCK_ID_alter().
*
* Enhance the Views exposed filter blocks.
*/
function social_search_block_view_views_exposed_filter_block_alter(array &$build, BlockPluginInterface $block) {
$filter_blocks = [
'search_content-page',
'search_users-page',
];
if (in_array($build['#derivative_plugin_id'], $filter_blocks)) {
// Disable cache for exposed filter block to get correct current path,
// which is used in $form['#action'].
$build['#cache'] = [
'max-age' => 0,
];
}
}
/**
* Implements hook_block_view_BASE_BLOCK_ID_alter().
*
* Make the label/title translatable.
*/
function social_block_view_search_hero_block_alter(array &$build, BlockPluginInterface $block) {
$build['#configuration']['label'] = t('Search');
}
Functions
Name | Description |
---|---|
social_block_view_search_hero_block_alter | Implements hook_block_view_BASE_BLOCK_ID_alter(). |
social_search_block_view_views_exposed_filter_block_alter | Implements hook_block_view_BASE_BLOCK_ID_alter(). |
social_search_form_views_exposed_form_alter | Implements hook_form_FORM_ID_alter(). |