search_langcode_test.module

Same filename in other branches
  1. 9 core/modules/search/tests/modules/search_langcode_test/search_langcode_test.module
  2. 8.9.x core/modules/search/tests/modules/search_langcode_test/search_langcode_test.module
  3. 11.x core/modules/search/tests/modules/search_langcode_test/search_langcode_test.module

Tests the preprocessing of search text.

Preprocessing is tested when the language code is passed to the preprocess hook and also when with alternate verb forms for the stemming test.

File

core/modules/search/tests/modules/search_langcode_test/search_langcode_test.module

View source
<?php


/**
 * @file
 * Tests the preprocessing of search text.
 *
 * Preprocessing is tested when the language code is passed to the preprocess
 * hook and also when with alternate verb forms for the stemming test.
 */

/**
 * Implements hook_search_preprocess().
 */
function search_langcode_test_search_preprocess($text, $langcode = NULL) {
    if (isset($langcode) && $langcode == 'en') {
        // Add the alternate verb forms for the word "testing".
        if ($text == 'we are testing') {
            $text .= ' test tested';
        }
        else {
            \Drupal::messenger()->addStatus('Langcode Preprocess Test: ' . $langcode);
            $text .= 'Additional text';
        }
    }
    elseif (isset($langcode)) {
        \Drupal::messenger()->addStatus('Langcode Preprocess Test: ' . $langcode);
        // Preprocessing for the excerpt test.
        if ($langcode == 'ex') {
            $text = str_replace('finding', 'find', $text);
            $text = str_replace('finds', 'find', $text);
            $text = str_replace('dic', ' dependency injection container', $text);
            $text = str_replace('hypertext markup language', 'html', $text);
        }
    }
    return $text;
}

Functions

Title Deprecated Summary
search_langcode_test_search_preprocess Implements hook_search_preprocess().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.