toggle search filers display

This commit is contained in:
Bachir Soussi Chiadmi 2021-05-19 18:21:29 +02:00
parent 9ff6e71eed
commit a36c19b21a
7 changed files with 60 additions and 6 deletions

View File

@ -8,6 +8,8 @@
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
use Drupal\search_api\Query\QueryInterface; use Drupal\search_api\Query\QueryInterface;
use Drupal\Core\Template\Attribute;
/** /**
* Implements hook_help(). * Implements hook_help().
*/ */
@ -48,3 +50,20 @@ function materio_sapi_search_api_solr_query_alter(Query $solarium_query, QueryI
} }
} }
/**
* Prepares variables for fieldset element templates.
*
* Default template: fieldset.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #attributes, #children, #description, #id, #title,
* #value.
*/
function materio_sapi_preprocess_fieldset(&$variables) {
if (isset($variables['element']['#legend_attributes'])) {
$variables['legend']['attributes'] = new Attribute($variables['element']['#legend_attributes']);
}
}

View File

@ -47,9 +47,18 @@ class MaterioSapiSearchForm extends FormBase {
]; ];
$form['filters'] = [ $form['filters'] = [
'#type' => 'container' '#type' => 'fieldset',
'#title' => t('Assisted Search'),
'#legend_attributes' => [
"class" => ["test-attribute"],
'@click.prevent' => "onClickFilters",
]
]; ];
// $form['filters']['switch'] = [
// '#type' => "label",
//
// ]
$query = \Drupal::entityQuery('taxonomy_term'); $query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', "assisted_research"); $query->condition('vid', "assisted_research");
$tids = $query->execute(); $tids = $query->execute();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -595,9 +595,30 @@ header[role="banner"]{
color:#666; color:#666;
} }
#edit-filters{ fieldset#edit-filters{
grid-row: 2 / 2; grid-row: 2 / 2;
grid-column: 1 / span 2; grid-column: 1 / span 2;
border: none;
padding: 0;
>legend{
line-height: 0.6;
padding-bottom: 0.2em;
width: 100%;
text-align: right;
span{
cursor: pointer;
font-size: 0.756em;
color: #8f8f8f;
}
}
> div.fieldset-wrapper{
height: 0;
overflow: hidden;
}
&.open >div.fieldset-wrapper{
height: auto;
overflow: visible;
}
.ss-main{ .ss-main{
font-size: 0.756em; font-size: 0.756em;
.ss-single-selected{ .ss-single-selected{

View File

@ -71,6 +71,11 @@ export default {
onSelectFiltersChange(index, info){ onSelectFiltersChange(index, info){
console.log('onSelectFiltersChange', index, info, this.filters) console.log('onSelectFiltersChange', index, info, this.filters)
this.slimFilters[index] = info.value this.slimFilters[index] = info.value
},
onClickFilters(e){
console.log('onClickFilters legend', e)
e.target.closest('fieldset').classList.toggle('open')
// TODO: reset the filters oon close
} }
}, },
directives: { directives: {