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

Issue #3171391 by mglaman: Only allow JSON:API widget for facets

parent fc6e8eaa
No related branches found
No related tags found
No related merge requests found
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\facets\FacetInterface;
use Drupal\facets\FacetSourceInterface;
use Drupal\jsonapi\Query\Filter;
......@@ -17,6 +18,20 @@ function jsonapi_search_api_facets_form_facet_source_edit_form_alter(&$form, For
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function jsonapi_search_api_facets_form_facets_facet_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
foreach ($form['widget']['#options'] as $plugin_id => $plugin_name) {
if (strpos($plugin_id, 'jsonapi_') !== 0) {
unset($form['widget']['#options'][$plugin_id]);
}
}
// Empty behaviors have no effect over JSON:API
$form['facet_settings']['empty_behavior']['#access'] = FALSE;
$form['facet_settings']['empty_behavior_container']['#access'] = FALSE;
}
/**
* Implements hook_ENTITY_TYPE_presave().
*
......@@ -28,3 +43,15 @@ function jsonapi_search_api_facets_facet_source_presave(FacetSourceInterface $en
$entity->setUrlProcessor('json_api');
}
}
/**
* Implements hook_ENTITY_TYPE_presave().
*
*/
function jsonapi_search_api_facets_facets_facet_presave(FacetInterface $entity) {
if (strpos($entity->getFacetSourceId(), 'jsonapi_search_api_facets') === 0) {
if (empty($entity->getWidget())) {
$entity->setWidget('jsonapi_search_api');
}
}
}
......@@ -69,8 +69,6 @@ final class IndexFacetsTest extends BrowserTestBase {
FacetSource::create([
'id' => 'jsonapi_search_api_facets__database_search_index',
'name' => 'jsonapi_search_api_facets:database_search_index',
'filter_key' => 'filter',
'url_processor' => 'json_api',
])->save();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment