From 43a8daff8acd4d6b791e29c608922a6c14a7012f Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 20 May 2021 20:12:41 +0200 Subject: [PATCH] translated terms in assisted search --- .../materio_sapi/src/Form/MaterioSapiSearchForm.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/modules/custom/materio_sapi/src/Form/MaterioSapiSearchForm.php b/web/modules/custom/materio_sapi/src/Form/MaterioSapiSearchForm.php index 0266228..e69b339 100644 --- a/web/modules/custom/materio_sapi/src/Form/MaterioSapiSearchForm.php +++ b/web/modules/custom/materio_sapi/src/Form/MaterioSapiSearchForm.php @@ -22,6 +22,8 @@ class MaterioSapiSearchForm extends FormBase { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { + $lang = \Drupal::languageManager()->getCurrentLanguage()->getId(); + $form['search'] = [ '#type' => 'textfield', // '#title' => $this->t('Search'), @@ -66,10 +68,16 @@ class MaterioSapiSearchForm extends FormBase { $terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids); foreach ($terms as $tid => $term) { - $childs = $term->get('field_terms')->getValue(); + if($term->hasTranslation($lang)){ + $term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $lang); + } $options = array($term->getName()); + $childs = $term->get('field_terms')->getValue(); foreach ($childs as $child) { $child_term = \Drupal\taxonomy\Entity\Term::load($child['target_id']); + if($child_term->hasTranslation($lang)){ + $child_term = \Drupal::service('entity.repository')->getTranslationFromContext($child_term, $lang); + } $options[$child_term->id()] = $child_term->getName(); } $form['filters']['filter-'.$tid] = array(