Skip to content
Snippets Groups Projects
Commit fc6e8eaa authored by Matt Glaman's avatar Matt Glaman Committed by Matt Glaman
Browse files

Issue #3171379 by mglaman: Facet source should be automatically configured

parent 693e2e47
Branches
Tags
No related merge requests found
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\facets\FacetSourceInterface;
use Drupal\jsonapi\Query\Filter;
/**
* Implements hook_form_FORM_ID_alter().
*/
function jsonapi_search_api_facets_form_facet_source_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['filter_key']['#disabled'] = TRUE;
$form['breadcrumb']['#access'] = FALSE;
foreach ($form['url_processor']['#options'] as $plugin_id => $plugin_name) {
if ($plugin_id !== 'json_api') {
unset($form['url_processor']['#options'][$plugin_id]);
}
}
}
/**
* Implements hook_ENTITY_TYPE_presave().
*
* @todo use hook_ENTITY_TYPE_create() after https://www.drupal.org/project/facets/issues/3171382
*/
function jsonapi_search_api_facets_facet_source_presave(FacetSourceInterface $entity) {
if (strpos($entity->getName(), 'jsonapi_search_api_facets:') === 0) {
$entity->setFilterKey(Filter::KEY_NAME);
$entity->setUrlProcessor('json_api');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment