lunr-8.x-1.0/modules/lunr_facet_example/lunr_facet_example.module
modules/lunr_facet_example/lunr_facet_example.module
<?php
/**
* @file
* Contains hook implementations for the Lunr Facet Example module.
*/
use Drupal\lunr\LunrSearchInterface;
/**
* Implements hook_lunr_search_page_alter().
*/
function lunr_facet_example_lunr_search_page_alter(&$build, LunrSearchInterface $lunr_search) {
// Add a custom input to the search page.
if ($lunr_search->id() === 'facet_example') {
$build['form']['type'] = [
'#type' => 'select',
'#title' => t('Type'),
'#options' => [
'' => t('Any'),
],
'#attributes' => [
'data-lunr-search-field' => 'type',
],
'#cache' => [
'tags' => \Drupal::entityTypeManager()->getDefinition('node_type')->getListCacheTags(),
],
];
foreach (\Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple() as $type) {
$build['form']['type']['#options'][$type->id()] = $type->label();
}
}
}
