1 Commits
Author SHA1 Message Date
bachirandClaude Opus 5.5 fca4be3155 Remove the former search form, filters and SlimSelect (F2)
- materio_sapi: MaterioSapiSearchForm, AjaxSearchForm and the
  /materio_sapi/search_form route removed, with the fieldset legend hook
  they needed. The search block is only the place where the Vue field
  mounts (placement and access unchanged).
- materiotheme: filters removed from the search store and Base.vue (the
  parameter of former URLs is ignored), formhtml removed from main.js and
  SearchBlock.vue, filter styles and SlimSelect import removed.
- slim-select uninstalled, with its postinstall patch step.
- Production build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
2026-11-17 21:11:18 +01:00
29 changed files with 26 additions and 406 deletions
-9
View File
@@ -7,7 +7,6 @@
"": { "": {
"name": "materio.com", "name": "materio.com",
"version": "1.1.0", "version": "1.1.0",
"hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.0", "axios": "^0.21.0",
@@ -59,7 +58,6 @@
"mini-css-extract-plugin": "^1.3.1", "mini-css-extract-plugin": "^1.3.1",
"querystring-es3": "^0.2.1", "querystring-es3": "^0.2.1",
"sass-loader": "^10.1.0", "sass-loader": "^10.1.0",
"slim-select": "^2.11.0",
"style-loader": "^2.0.0", "style-loader": "^2.0.0",
"uglify-es": "^3.3.9", "uglify-es": "^3.3.9",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",
@@ -11061,13 +11059,6 @@
"url": "https://github.com/chalk/slice-ansi?sponsor=1" "url": "https://github.com/chalk/slice-ansi?sponsor=1"
} }
}, },
"node_modules/slim-select": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/slim-select/-/slim-select-2.11.0.tgz",
"integrity": "sha512-Y0FEJKIPBy8ax7jArUxICxtKAnhX8GH7ydaFhcrYH7OznfpvxCe8uU2etyuRPKhE23c2LhT2GROFvZzGVplA0g==",
"dev": true,
"license": "MIT"
},
"node_modules/snapdragon": { "node_modules/snapdragon": {
"version": "0.8.2", "version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
+1 -3
View File
@@ -9,8 +9,7 @@
"lint": "eslint --ext .js,.vue src", "lint": "eslint --ext .js,.vue src",
"lint:fix": "eslint --ext .js,.vue src --fix", "lint:fix": "eslint --ext .js,.vue src --fix",
"test": "jest --config test/jest.config.js", "test": "jest --config test/jest.config.js",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand --config test/jest.config.js", "test:debug": "node --inspect node_modules/.bin/jest --runInBand --config test/jest.config.js"
"postinstall": "patch --forward node_modules/slim-select/package.json < patches/slimselect-export-css.patch"
}, },
"keywords": [ "keywords": [
"Vue", "Vue",
@@ -68,7 +67,6 @@
"mini-css-extract-plugin": "^1.3.1", "mini-css-extract-plugin": "^1.3.1",
"querystring-es3": "^0.2.1", "querystring-es3": "^0.2.1",
"sass-loader": "^10.1.0", "sass-loader": "^10.1.0",
"slim-select": "^2.11.0",
"style-loader": "^2.0.0", "style-loader": "^2.0.0",
"uglify-es": "^3.3.9", "uglify-es": "^3.3.9",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",
@@ -8,7 +8,6 @@
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().
@@ -51,24 +50,6 @@ 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']);
}
}
// ? https://happyculture.coop/blog/drupal-8-declarer-un-champ-extrafield-calcule-computed-field // ? https://happyculture.coop/blog/drupal-8-declarer-un-champ-extrafield-calcule-computed-field
// ? https://fivejars.com/blog/entity-basefielddefinitions-fields-examples-drupal-8 // ? https://fivejars.com/blog/entity-basefielddefinitions-fields-examples-drupal-8
/** /**
@@ -6,22 +6,6 @@ materio_sapi.search_autocomplete:
requirements: requirements:
_permission: 'access materio search' _permission: 'access materio search'
materio_sapi.search_form:
path: '/materio_sapi/search_form'
defaults:
_controller: '\Drupal\materio_sapi\Controller\AjaxSearchForm::getForm'
_format: json
requirements:
_permission: 'access materio search'
# materio_sapi.materio_sapi_search_form:
# path: '/materio_sapi/form/materio_sapi_search'
# defaults:
# _form: '\Drupal\materio_sapi\Form\MaterioSapiSearchForm'
# _title: 'MaterioSapiSearchForm'
# requirements:
# _access: 'TRUE'
materio_sapi.getresults: materio_sapi.getresults:
path: '/materio_sapi/getresults' path: '/materio_sapi/getresults'
defaults: defaults:
@@ -1,92 +0,0 @@
<?php
// https://www.qed42.com/blog/autocomplete-drupal-8
// https://www.drupal.org/docs/8/modules/search-api/developer-documentation/executing-a-search-in-code
namespace Drupal\materio_sapi\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormBuilder;
use Drupal\Core\Form\FormState;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\core\render\RenderContext;
/**
* Defines a route controller for entity autocomplete form elements.
*/
class AjaxSearchForm extends ControllerBase {
/**
* The built form array.
*
* @var array
*/
protected $form_builded;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilder
*/
protected $formBuilder;
/**
* Construct.
*/
public function __construct(FormBuilder $formBuilder) {
$this->formBuilder = $formBuilder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('form_builder')
);
}
private function getFormDefinition(){
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
\Drupal::logger('materio_sapi')->notice($language);
// $form_state = new FormState();
$this->form_builded = $this->formBuilder->getForm('Drupal\materio_sapi\Form\MaterioSapiSearchForm', $language);
}
/**
* Handler for getform request.
*/
public function getForm(Request $request) {
$this->getFormDefinition();
// $rendered = render($this->form_builded);
$rendered = \Drupal::service('renderer')->render($this->form_builded);
// $form_builded = $this->form_builded;
// $rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($form_builded) {
// return render($form_builded);
// });
$data = [
'rendered' => $rendered,
// '#cache' => [
// 'max-age' => \Drupal\Core\Cache\Cache::PERMANENT,
// 'tags' => [
// 'materio_sapi-search_form-cache',
// ]
// ]
];
$response = new JsonResponse();
$response->setData($data);
// $response = new CacheableJsonResponse($data);
// $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
return $response;
}
}
@@ -1,151 +0,0 @@
<?php
namespace Drupal\materio_sapi\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class MaterioSapiSearchForm.
*/
class MaterioSapiSearchForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'materio_sapi_search_form';
}
/**
* {@inheritdoc}
*/
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'),
'#maxlength' => 150,
'#size' => 25,
'#weight' => '0',
'#attributes' => [
"placeholder" => $this->t('Search'),
// "@keyup" => "keyup",
// "@keyup.enter" => "submit",
"v-model" => "typed",
"v-focus" => "",
// "v-on:select" => "typed",
],
'#autocomplete_route_name' => 'materio_sapi.search_autocomplete',
];
$form['searchautocomplete'] = [
'#type' => 'hidden',
'#attributes' => [
"v-model" => "autocomplete"
],
];
// $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
]
];
// $form['filters']['switch'] = [
// '#type' => "label",
//
// ]
$query = \Drupal::entityQuery('taxonomy_term')
->condition('vid', "assisted_research")
->accessCheck(TRUE)
->sort('field_weight', 'ASC');
$tids = $query->execute();
$terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);
foreach ($terms as $tid => $term) {
if($term->hasTranslation($lang)){
$term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $lang);
}
$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,
'#value' => $selected
);
}
$form['submit'] = array(
'#type' => 'button',
// '#src' => '',//drupal_get_path('module', 'materio_search_api') . '/images/search.png',
'#value' => t('Search'),
// '#prefix' => '<div class="search-btn-wrapper">',
// '#suffix'=> '</div>',
'#attributes' => [
'title' => t('Search'),
'@click.prevent' => "submit",
]
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Display result.
foreach ($form_state->getValues() as $key => $value) {
\Drupal::messenger()->addStatus($key . ': ' . $value);
}
}
}
@@ -20,11 +20,16 @@ class MaterioSapiSearchBlock extends BlockBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function build() { public function build() {
$build = []; // Only a place in the page: the search field is a Vue component
// $build['materio_sapi_search_block']['#markup'] = 'Implement MaterioSapiSearchBlock.'; // (materiotheme SearchForm.vue, F1) mounted on this block. Not empty,
$form = \Drupal::formBuilder()->getForm('Drupal\materio_sapi\Form\MaterioSapiSearchForm'); // otherwise Drupal would not render the block.
$build['materio_sapi_search_block'] = $form; return [
return $build; 'placeholder' => [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => ['class' => ['materio-sapi-search-placeholder']],
],
];
} }
/** /**
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
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
File diff suppressed because one or more lines are too long
@@ -381,12 +381,9 @@ export let _v_sitebranding_block, _v_user_block, _v_header_menu, _v_language_swi
// console.log('router beforeEach to ', to) // console.log('router beforeEach to ', to)
const id = 'block-materiosapisearchblock' const id = 'block-materiosapisearchblock'
let $search_block = document.getElementById(id) let $search_block = document.getElementById(id)
let formhtml = null // The block is only a place in the page: the search form is the Vue
if ($search_block) { // component SearchForm (F1).
// get the search form html to pass it as template to the vue if (!$search_block) {
// we gain display speed vs async downloaded data
formhtml = $search_block.innerHTML
} else {
// else create the empty block to fill it later with async data // else create the empty block to fill it later with async data
$search_block = document.createElement('div') $search_block = document.createElement('div')
$search_block.setAttribute('id', id) $search_block.setAttribute('id', id)
@@ -399,7 +396,7 @@ export let _v_sitebranding_block, _v_user_block, _v_header_menu, _v_language_swi
_v_search_block = new Vue({ _v_search_block = new Vue({
store, store,
i18n, i18n,
render: h => h(VSearchBlock, { props: { blockid: id, formhtml: formhtml } }) render: h => h(VSearchBlock, { props: { blockid: id } })
}).$mount('#' + id) }).$mount('#' + id)
} }
function initVLeftContent () { function initVLeftContent () {
@@ -1,10 +1,6 @@
@use "sass:math"; @use "sass:math";
@use "sass:color"; @use "sass:color";
// @import '~slim-select/scss';
@import 'slim-select/styles';
$mdi-font-path: './mdi/fonts/'; $mdi-font-path: './mdi/fonts/';
@import './mdi/css/materialdesignicons.css'; @import './mdi/css/materialdesignicons.css';
@import './mdi/scss/variables'; @import './mdi/scss/variables';
@@ -641,72 +637,6 @@ header[role="banner"]{
} }
} }
fieldset#edit-filters{
grid-row: 2 / 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{
font-size: 0.756em;
.ss-single-selected{
border-radius: 0.7em;
&.ss-open-below{
border-radius: 0.7em 0.7em 0 0.7em;
}
height:1.5em;
border: none;
padding: 0 0.5em;
background-color: #eeeaea;
span.placeholder{
color: $color-main-text;
line-height: 1;
span.ss-disabled{
color: #8f8f8f;
}
}
span.ss-arrow span{
border-color: #b1adad;
}
}
.ss-content{
width:auto;
border: none;
border-radius: 0.7em 0 0.7em 0.7em;
&.ss-open{
box-shadow: 0 0 10px #ccc;
}
right: 0;
.ss-list{
max-height: none;
.ss-option{
white-space: nowrap;
text-align: right;
}
}
}
}
}
.button.form-submit{ .button.form-submit{
grid-row: 1 / 1; grid-row: 1 / 1;
grid-column: 2 / 2; grid-column: 2 / 2;
@@ -9,9 +9,7 @@ import SearchForm from 'vuejs/components/Form/SearchForm'
import { mapState } from 'vuex' import { mapState } from 'vuex'
export default { export default {
// formhtml: HTML of the former Drupal form, still passed by main.js, no props: ['blockid'],
// longer used: the form is a Vue component (F1).
props: ['blockid', 'formhtml'],
computed: { computed: {
...mapState({ ...mapState({
canSearch: state => state.User.canSearch canSearch: state => state.User.canSearch
@@ -60,7 +60,7 @@ export default {
// Hide the keyboard on mobile devices. // Hide the keyboard on mobile devices.
this.$refs.input.blur() this.$refs.input.blur()
// Base.vue reacts to the route change and runs the search. // Base.vue reacts to the route change and runs the search.
// Only the phrase: no more terms (F7) nor filters (F2). // Only the phrase: no more terms (F7) nor filters.
this.$router.push({ name: 'base', query: phrase ? { keys: phrase } : {} }) this.$router.push({ name: 'base', query: phrase ? { keys: phrase } : {} })
.catch(() => {}) .catch(() => {})
} }
@@ -92,11 +92,7 @@ export default {
this.$store.commit('Search/reSetTerms') this.$store.commit('Search/reSetTerms')
} }
if (params.has('filters')) { // The filters parameter of former URLs is ignored (F2).
this.$store.commit('Search/setFilters', params.get('filters').split(','))
} else {
this.$store.commit('Search/reSetFilters')
}
this.newSearch() this.newSearch()
}, },
@@ -113,11 +109,6 @@ export default {
}else{ }else{
this.$store.commit('Search/reSetTerms') this.$store.commit('Search/reSetTerms')
} }
if (to.query.hasOwnProperty('filters')) {
this.$store.commit('Search/setFilters', to.query.filters)
}else{
this.$store.commit('Search/reSetFilters')
}
if (to.query.hasOwnProperty('keys')) { if (to.query.hasOwnProperty('keys')) {
const r = /,\s?$/ const r = /,\s?$/
let keys = to.query.keys.replace(r,'').split(', ') let keys = to.query.keys.replace(r,'').split(', ')
@@ -17,7 +17,6 @@ export default {
state: { state: {
keys: [], keys: [],
terms: [], terms: [],
filters: [],
uuids: [], uuids: [],
items: [], items: [],
offset: 0, offset: 0,
@@ -92,13 +91,6 @@ export default {
reSetTerms (state) { reSetTerms (state) {
state.terms = [] state.terms = []
}, },
setFilters (state, filters) {
console.log('store search setFilters', filters)
state.filters = typeof filters === 'string' ? filters.split(',') : filters
},
reSetFilters (state) {
state.filters = []
},
setInfos (state, infos) { setInfos (state, infos) {
state.infos = infos state.infos = infos
}, },
@@ -169,10 +161,6 @@ export default {
limit: state.limit limit: state.limit
} }
console.log('search store getResults, params', params) console.log('search store getResults, params', params)
if (state.filters) {
console.log('getResults filters', state.filters)
params.filters = state.filters.join(',')
}
// console.log('Search getResults params', params) // console.log('Search getResults params', params)
const q = qs.stringify(params) const q = qs.stringify(params)
// * Qs.Stringify () Arrayformat: 'Repeat' : https://programmerall.com/article/31901061156/ // * Qs.Stringify () Arrayformat: 'Repeat' : https://programmerall.com/article/31901061156/