Commit 749c2c63 authored by borisson_'s avatar borisson_ Committed by borisson_
Browse files

Issue #2833291 by borisson_: Error when creating a summary block

parent 9fc5c4e7
......@@ -83,7 +83,7 @@ class FacetsSummary extends ConfigEntityBase implements FacetsSummaryInterface {
*
* @var string[]
*/
protected $facets;
protected $facets = [];
/**
* Cached information about the processors available for this facet.
......@@ -158,7 +158,7 @@ class FacetsSummary extends ConfigEntityBase implements FacetsSummaryInterface {
/**
* {@inheritdoc}
*/
public function setFacets($facets) {
public function setFacets(array $facets) {
return $this->facets = $facets;
}
......
......@@ -72,7 +72,7 @@ interface FacetsSummaryInterface extends ConfigEntityInterface {
* - suffix: (string) Suffix of facet group.
* - separator: (string) Separator for facet items.
*/
public function setFacets($facets);
public function setFacets(array $facets);
/**
* Removes a facet from the list.
......
......@@ -114,7 +114,6 @@ class FacetsSummaryForm extends EntityForm {
/** @var \Drupal\facets_summary\FacetsSummaryInterface $facets_summary */
$facets_summary = $this->entity;
$all_processors = $facets_summary->getProcessors(FALSE);
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'facets/drupal.facets.index-active-formatters';
......@@ -141,47 +140,54 @@ class FacetsSummaryForm extends EntityForm {
$facets = $facets_summary->getFacets();
$default_facets = array_keys($facets);
foreach ($this->facetManager->getFacetsByFacetSourceId($facets_summary->getFacetSourceId()) as $facet) {
if (!in_array($facet->id(), $default_facets)) {
$facets[$facet->id()] = [
'label' => $facet->getName(),
'separator' => ', ',
'show_count' => FALSE,
$all_facets = $this->facetManager->getFacetsByFacetSourceId($facets_summary->getFacetSourceId());
if (!empty($all_facets)) {
foreach ($all_facets as $facet) {
if (!in_array($facet->id(), $default_facets)) {
$facets[$facet->id()] = [
'label' => $facet->getName(),
'separator' => ', ',
'show_count' => FALSE,
];
}
$facets[$facet->id()]['name'] = $facet->getName();
}
foreach ($facets as $id => $facet) {
$form['facets'][$id] = [
'checked' => [
'#type' => 'checkbox',
'#title' => $facet['name'],
'#default_value' => in_array($id, $default_facets),
],
'label' => [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#default_value' => $facet['label'],
'#size' => 25,
],
'separator' => [
'#type' => 'textfield',
'#title' => $this->t('Separator'),
'#default_value' => $facet['separator'],
'#size' => 8,
],
'show_count' => [
'#type' => 'checkbox',
'#default_value' => $facet['show_count'],
],
'weight' => [
'#type' => 'weight',
'#title' => $this->t('Weight for @title', ['@title' => $facet['name']]),
'#title_display' => 'invisible',
'#attributes' => ['class' => ['facets-order-weight']],
],
'#attributes' => ['class' => ['draggable']],
];
}
$facets[$facet->id()]['name'] = $facet->getName();
}
foreach ($facets as $id => $facet) {
$form['facets'][$id] = [
'checked' => [
'#type' => 'checkbox',
'#title' => $facet['name'],
'#default_value' => in_array($id, $default_facets),
],
'label' => [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#default_value' => $facet['label'],
'#size' => 25,
],
'separator' => [
'#type' => 'textfield',
'#title' => $this->t('Separator'),
'#default_value' => $facet['separator'],
'#size' => 8,
],
'show_count' => [
'#type' => 'checkbox',
'#default_value' => $facet['show_count'],
],
'weight' => [
'#type' => 'weight',
'#title' => $this->t('Weight for @title', ['@title' => $facet['name']]),
'#title_display' => 'invisible',
'#attributes' => ['class' => ['facets-order-weight']],
],
'#attributes' => ['class' => ['draggable']],
];
else {
$form['facets'] = ['#markup' => $this->t('No facets found.')];
}
// Retrieve lists of all processors, and the stages and weights they have.
......@@ -225,6 +231,8 @@ class FacetsSummaryForm extends EntityForm {
),
);
$form['facets_summary_settings'][$processor_id]['settings'] = [];
$processor_form_state = SubformState::createForSubform($form['facets_summary_settings'][$processor_id]['settings'], $form, $form_state);
$processor_form = $processor->buildConfigurationForm($form, $processor_form_state, $facets_summary);
if ($processor_form) {
......@@ -348,6 +356,7 @@ class FacetsSummaryForm extends EntityForm {
// Iterate over all processors that have a form and are enabled.
foreach ($form['facets_summary_settings'] as $processor_id => $processor_form) {
if (!empty($values['processors'][$processor_id])) {
$processor_form_state = SubformState::createForSubform($form['facets_summary_settings'][$processor_id]['settings'], $form, $form_state);
$processors[$processor_id]->validateConfigurationForm($form['facets_summary_settings'][$processor_id], $processor_form_state, $facets_summary);
}
......@@ -392,8 +401,9 @@ class FacetsSummaryForm extends EntityForm {
}
$facets_summary->addProcessor($new_settings);
}
// Set our Facet Config.
$facets_summary->setFacets($form_state->getValue(['facets']));
$facets_summary->setFacets((array) $form_state->getValue(['facets']));
$facets_summary->save();
drupal_set_message(t('Facets Summary %name has been updated.', ['%name' => $facets_summary->getName()]));
......
<?php
namespace Drupal\facets_summary\Tests;
use Drupal\facets\Tests\WebTestBase as FacetTestBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Tests the overall functionality of the Facets summary admin UI.
*
* @group facets
*/
class IntegrationTest extends FacetTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'facets_summary',
];
/**
* No config checking.
*
* @todo Enable config checking again.
*
* @var bool
*/
protected $strictConfigSchema = FALSE;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->drupalLogin($this->adminUser);
$this->setUpExampleStructure();
$this->insertExampleContent();
$this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.');
// Make absolutely sure the ::$blocks variable doesn't pass information
// along between tests.
$this->blocks = NULL;
}
/**
* {@inheritdoc}
*/
protected function installModulesFromClassProperty(ContainerInterface $container) {
// This will just set the Drupal state to include the necessary bundles for
// our test entity type. Otherwise, fields from those bundles won't be found
// and thus removed from the test index. (We can't do it in setUp(), before
// calling the parent method, since the container isn't set up at that
// point.)
$bundles = array(
'entity_test_mulrev_changed' => array('label' => 'Entity Test Bundle'),
'item' => array('label' => 'item'),
'article' => array('label' => 'article'),
);
\Drupal::state()->set('entity_test_mulrev_changed.bundles', $bundles);
parent::installModulesFromClassProperty($container);
}
/**
* Tests the overall functionality of the Facets summary admin UI.
*/
public function testFramework() {
$this->drupalGet('admin/config/search/facets');
$this->assertNoText('Facets Summary');
$values = [
'name' => 'Owl',
'id' => 'owl',
'facet_source_id' => 'views_page:search_api_test_view__page_1',
];
$this->drupalPostForm('admin/config/search/facets/add-facet-summary', $values, 'Save');
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalGet('admin/config/search/facets');
$this->assertText('Facets Summary');
$this->assertText('Owl');
$this->drupalGet('admin/config/search/facets/facet-summary/owl/edit');
$this->assertText('No facets found.');
$this->createFacet('Llama', 'llama');
$this->drupalGet('admin/config/search/facets');
$this->assertText('Llama');
$this->drupalGet('admin/config/search/facets/facet-summary/owl/edit');
$this->assertNoText('No facets found.');
$this->assertText('Llama');
}
}
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