translated terms in assisted search
This commit is contained in:
parent
a4baf0d6a6
commit
43a8daff8a
|
@ -22,6 +22,8 @@ class MaterioSapiSearchForm extends FormBase {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||||
|
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||||
|
|
||||||
$form['search'] = [
|
$form['search'] = [
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
// '#title' => $this->t('Search'),
|
// '#title' => $this->t('Search'),
|
||||||
|
@ -66,10 +68,16 @@ class MaterioSapiSearchForm extends FormBase {
|
||||||
$terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);
|
$terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);
|
||||||
|
|
||||||
foreach ($terms as $tid => $term) {
|
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());
|
$options = array($term->getName());
|
||||||
|
$childs = $term->get('field_terms')->getValue();
|
||||||
foreach ($childs as $child) {
|
foreach ($childs as $child) {
|
||||||
$child_term = \Drupal\taxonomy\Entity\Term::load($child['target_id']);
|
$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();
|
$options[$child_term->id()] = $child_term->getName();
|
||||||
}
|
}
|
||||||
$form['filters']['filter-'.$tid] = array(
|
$form['filters']['filter-'.$tid] = array(
|
||||||
|
|
Loading…
Reference in New Issue