@@ -9,6 +9,7 @@ use Solarium\Core\Query\QueryInterface;
9
9
use Drupal\search_api\Query\QueryInterface as SearchApiQueryInterface;
10
10
use Drupal\Core\Language\Language;
11
11
use Drupal\Component\Utility\Html;
12
+ use \Drupal\Core\StringTranslation\TranslatableMarkup;
12
13
13
14
/**
14
15
* Implements hook_preprocess_views_view() for views_view.
@@ -162,12 +163,19 @@ function unity_search_pages_preprocess_block(&$variables) {
162
163
*/
163
164
function unity_search_pages_preprocess_page_title(&$variables) {
164
165
$current_route = \Drupal::routeMatch()->getRouteName();
165
- $title = $variables['title'];
166
+ $title_raw = $variables['title'];
166
167
$pattern = '/view.\w*search.\w*search_page/';
167
168
168
169
if (preg_match($pattern, $current_route)) {
169
- if (preg_match('/\w*\b\s- search results/', $title)) {
170
- $new_title = strtok($title, ' -');
170
+ if ($title_raw instanceof TranslatableMarkup) {
171
+ $title_text = $title_raw->render();
172
+ } elseif (is_array($title_raw) && isset($title_raw['#markup'])) {
173
+ $title_text = $title_raw['#markup'];
174
+ } else {
175
+ $title_text = $title_raw;
176
+ }
177
+ if (preg_match('/\w*\b\s- search results/', $title_text)) {
178
+ $new_title = strtok($title_text, ' -');
171
179
$variables['title'] = t($new_title);
172
180
$variables['title_subtitle'] = t('search results');
173
181
}
0 commit comments