translated terms in assisted search

This commit is contained in:
Bachir Soussi Chiadmi 2021-05-20 20:12:41 +02:00
parent a4baf0d6a6
commit 43a8daff8a
1 changed files with 9 additions and 1 deletions

View File

@ -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(