|
@@ -24,6 +24,18 @@ class MaterioSapiSearchForm extends FormBase {
|
|
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
|
|
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
|
|
|
|
|
+ $keys = \Drupal::request()->get('keys');
|
|
|
+ $term = \Drupal::request()->get('term');
|
|
|
+ $filters = \Drupal::request()->get('filters');
|
|
|
+
|
|
|
+ $form['#cache'] = array(
|
|
|
+ 'contexts' => array(
|
|
|
+ 'url.query_args:keys',
|
|
|
+ 'url.query_args:term',
|
|
|
+ 'url.query_args:filters',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
$form['search'] = [
|
|
|
'#type' => 'textfield',
|
|
|
// '#title' => $this->t('Search'),
|
|
@@ -48,12 +60,21 @@ class MaterioSapiSearchForm extends FormBase {
|
|
|
],
|
|
|
];
|
|
|
|
|
|
+ // $filters_array = [];
|
|
|
+ $filters_classes = [];
|
|
|
+ if($filters){
|
|
|
+ $filters_array = explode(',',$filters);
|
|
|
+ $filters_classes[] = 'open';
|
|
|
+ }
|
|
|
$form['filters'] = [
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => t('filters'),
|
|
|
'#legend_attributes' => [
|
|
|
"class" => ["test-attribute"],
|
|
|
'@click.prevent' => "onClickFilters",
|
|
|
+ ],
|
|
|
+ '#attributes' => [
|
|
|
+ "class" => $filters_classes
|
|
|
]
|
|
|
];
|
|
|
|
|
@@ -73,18 +94,23 @@ class MaterioSapiSearchForm extends FormBase {
|
|
|
}
|
|
|
$options = array($term->getName());
|
|
|
$childs = $term->get('field_terms')->getValue();
|
|
|
+ $selected = null;
|
|
|
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();
|
|
|
+ if (isset($filters_array) && in_array($child_term->id(), $filters_array)) {
|
|
|
+ $selected = $child_term->id();
|
|
|
+ }
|
|
|
}
|
|
|
$form['filters']['filter-'.$tid] = array(
|
|
|
'#type' => 'select',
|
|
|
// '#title' => $term->getName(),
|
|
|
// '#multiple' => true,
|
|
|
- '#options' => $options
|
|
|
+ '#options' => $options,
|
|
|
+ '#value' => $selected
|
|
|
);
|
|
|
}
|
|
|
|