Files
materio-d9/web/modules/custom/materio_sapi/materio_sapi.module
T
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

111 lines
3.9 KiB
PHP

<?php
/**
* @file
* Contains materio_sapi.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Solarium\QueryType\Select\Query\Query;
use Drupal\search_api\Query\QueryInterface;
/**
* Implements hook_help().
*/
function materio_sapi_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the materio_sapi module.
case 'help.page.materio_sapi':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Search Api Materio module') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_search_api_solr_query_alter();
*/
function materio_sapi_search_api_solr_query_alter(Query $solarium_query, QueryInterface $query) {
if ($termid = (int)$query->getOption('termid')) {
// get solarium fileds name
$index = $query->getIndex();
$solrFields = $index->getServerInstance()
->getBackend()
->getSolrFieldNames($index);
// tag_tid"itm_tag_tid"
// thesaurus_tid"itm_thesaurus_tid"
$tag_fname = $solrFields['tag_tid'];
$thes_fname = $solrFields['thesaurus_tid'];
// $solarium_query->addParam('bf', "recip(abs(ms(NOW,{$solrField})),3.16e-11,10,0.1)");
// $bfparam = "if(or(gt(termfreq({$tag_fname},{$termid}),0),gt(termfreq({$thes_fname},{$termid}),0)),^21,0)";
$bfparam = "if(or(exists(query({$tag_fname}:{$termid})),exists(query({$thes_fname}:{$termid}))),^21,0)";
// boost=if(or(exists(query(itm_tag_tid:396)),exists(query(itm_thesaurus_tid:396))),^21,0 )
$solarium_query->addParam('boost', $bfparam);
// $solarium_query->addParam('debugQuery', 'on');
}
}
// ? https://happyculture.coop/blog/drupal-8-declarer-un-champ-extrafield-calcule-computed-field
// ? https://fivejars.com/blog/entity-basefielddefinitions-fields-examples-drupal-8
/**
* Implements hook_entity_bundle_field_info().
*/
function materio_sapi_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
$fields = [];
if ($entity_type->id() == 'node') {
if ($bundle == 'materiau') {
for ($i=0; $i < 5 ; $i++) {
$fields["thesaurus_$i"] = \Drupal\Core\Field\BaseFieldDefinition::create('entity_reference')
->setLabel(t("Thesaurus $i"))
->setComputed(TRUE)
->setSetting('target_type', 'taxonomy_term')
->setSetting('handler_settings',['target_bundles'=>['thesaurus'=>'thesaurus']] )
->setClass('\Drupal\materio_sapi\ThesaurusRefComputed')
->setDisplayConfigurable('view', FALSE);
}
$fields["field_country_name_computed"] = \Drupal\Core\Field\BaseFieldDefinition::create('string')
->setLabel(t("Country Name"))
->setComputed(TRUE)
->setTranslatable(TRUE)
->setClass('\Drupal\materio_sapi\CountryNameNodeComputed')
->setDisplayConfigurable('view', FALSE);
}
}
// if ($entity_type->id() == 'taxonomy_term') {
// if ($bundle == 'company') {
// $fields["field_country_name_computed"] = \Drupal\Core\Field\BaseFieldDefinition::create('string')
// ->setName('field_country_name_computed')
// ->setLabel(t("Country Name"))
// ->setComputed(TRUE)
// ->setTranslatable(TRUE)
// ->setClass('\Drupal\materio_sapi\CountryNameComputed')
// ->setDisplayConfigurable('view', FALSE);
// }
// }
return $fields;
}
// ? https://www.webomelette.com/creating-pseudo-fields-drupal-8
// /**
// * Implements hook_entity_extra_field_info().
// */
// function materio_sapi_entity_extra_field_info() {
// $extra = array();
// foreach (NodeType::loadMultiple() as $bundle) {
// $extra['node'][$bundle->Id()]['display']['my_own_pseudo_field'] = array(
// 'label' => t('My own field'),
// 'description' => t('This is my own pseudo-field'),
// 'weight' => 100,
// 'visible' => false,
// );
// }
// return $extra;
// }