Commit 6176adf8 authored by idebr's avatar idebr Committed by StryKaizer

Issue #2937294 by idebr, borisson_: Display the facet's source on the facet edit form

parent f255925a
......@@ -6,6 +6,7 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay;
use Drupal\facets\FacetSource\SearchApiFacetSourceInterface;
use Drupal\search_api\Plugin\search_api\display\ViewsRest;
......@@ -28,7 +29,7 @@ class FacetForm extends EntityForm {
*
* @var \Drupal\facets\FacetInterface
*/
protected $facet;
protected $entity;
/**
* The processor manager.
......@@ -44,6 +45,13 @@ class FacetForm extends EntityForm {
*/
protected $widgetPluginManager;
/**
* The plugin manager for facet sources.
*
* @var \Drupal\facets\FacetSource\FacetSourcePluginManager
*/
protected $facetSourcePluginManager;
/**
* Constructs an FacetDisplayForm object.
*
......@@ -53,11 +61,14 @@ class FacetForm extends EntityForm {
* The processor plugin manager.
* @param \Drupal\facets\Widget\WidgetPluginManager $widget_plugin_manager
* The plugin manager for widgets.
* @param \Drupal\facets\FacetSource\FacetSourcePluginManager $facet_source_plugin_manager
* The plugin manager for facet sources.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ProcessorPluginManager $processor_plugin_manager, WidgetPluginManager $widget_plugin_manager) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, ProcessorPluginManager $processor_plugin_manager, WidgetPluginManager $widget_plugin_manager, FacetSourcePluginManager $facet_source_plugin_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->processorPluginManager = $processor_plugin_manager;
$this->widgetPluginManager = $widget_plugin_manager;
$this->facetSourcePluginManager = $facet_source_plugin_manager;
}
/**
......@@ -67,7 +78,8 @@ class FacetForm extends EntityForm {
return new static(
$container->get('entity_type.manager'),
$container->get('plugin.manager.facets.processor'),
$container->get('plugin.manager.facets.widget')
$container->get('plugin.manager.facets.widget'),
$container->get('plugin.manager.facets.facet_source')
);
}
......@@ -124,6 +136,18 @@ class FacetForm extends EntityForm {
/** @var \Drupal\facets\FacetInterface $facet */
$facet = $this->entity;
$facet_sources = [];
foreach ($this->facetSourcePluginManager->getDefinitions() as $facet_source_id => $definition) {
$facet_sources[$definition['id']] = !empty($definition['label']) ? $definition['label'] : $facet_source_id;
}
if (isset($facet_sources[$facet->getFacetSourceId()])) {
$form['facet_source'] = [
'#type' => 'item',
'#title' => $this->t('Facet source'),
'#markup' => $facet_sources[$facet->getFacetSourceId()],
];
}
$widget_options = [];
foreach ($this->widgetPluginManager->getDefinitions() as $widget_id => $definition) {
$widget_options[$widget_id] = !empty($definition['label']) ? $definition['label'] : $widget_id;
......
......@@ -1051,6 +1051,11 @@ class IntegrationTest extends FacetsTestBase {
// Make sure that the redirection back to the overview was successful and
// the edited facet is shown on the overview page.
$this->assertSession()->pageTextContains('Facet ' . $facet_name . ' has been updated.');
$facet_edit_page = '/admin/config/search/facets/' . $facet_id . '/edit';
$this->drupalGet($facet_edit_page);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('View Search API Test Fulltext search view, display Page');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment