Search default value translation not working

Created on 17 December 2024, 5 days ago

I have a multilingual website using the Search API with Solr for views. I can't find where to translate the default value for the search input.

In the SearchApiFulltext.php file, I tried updating line 303 from '#default_value' => $this->value to '#default_value' => $this->t($this->value). However, this resulted in a memory overflow, and the translation didn't work. Does anyone have any ideas on how to resolve this? Many thanks in advance!

  // modules > contrib > search_api > src > Plugin > views > filter > SearchApiFulltext.php
  protected function valueForm(&$form, FormStateInterface $form_state) {
    parent::valueForm($form, $form_state);

    $exposed = (bool) $form_state->get('exposed');
    $max_length = NULL;
    if ($exposed && $this->options['expose']['value_maxlength']) {
      $max_length = $this->options['expose']['value_maxlength'];
    }
    $form['value'] = [
      '#type' => 'textfield',
      '#title' => !$exposed ? $this->t('Value') : '',
      '#size' => 30,
      '#default_value' => $this->value,
      '#maxlength' => $max_length,
    ];
    if (!empty($this->options['expose']['placeholder'])) {
      $form['value']['#attributes']['placeholder'] = $this->options['expose']['placeholder'];
    }
  }
Feature request
Status

Needs work

Version

1.35

Component

Plugins

Created by

🇭🇰Hong Kong kkli2e

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024