Commit 31eb0676 authored by borisson_'s avatar borisson_ Committed by Nick_vh

Issue #2877634 by borisson_, andreasderijcke, swentel: The title variable is...

Issue #2877634 by borisson_, andreasderijcke, swentel: The title variable is not set/used. Templates/preprocess have no context
parent fdce82f1
......@@ -73,6 +73,9 @@ facets.facet.*:
show_only_one_result:
type: boolean
label: 'Show only one result'
show_title:
type: boolean
label: 'Show title'
processor_configs:
type: sequence
label: 'Processor settings'
......
......@@ -218,6 +218,9 @@ function facets_entity_predelete(EntityInterface $entity) {
* @see https://www.drupal.org/node/1842756
*/
function facets_preprocess_facets_item_list(array &$variables) {
if ($variables['facet'] !== NULL && $variables['facet']->get('show_title') === TRUE) {
$variables['title'] = $variables['facet']->label();
}
template_preprocess_item_list($variables);
}
......
......@@ -53,7 +53,8 @@ use Drupal\facets\FacetInterface;
* "exclude",
* "only_visible_when_facet_source_is_visible",
* "processor_configs",
* "empty_behavior"
* "empty_behavior",
* "show_title"
* },
* links = {
* "collection" = "/admin/config/search/facets",
......
......@@ -373,6 +373,12 @@ class FacetForm extends EntityForm {
'#maxlength' => 50,
'#required' => TRUE,
];
$form['facet_settings']['show_title'] = [
'#type' => 'checkbox',
'#title' => $this->t('Show title of facet'),
'#description' => $this->t('Show the title of the facet trough a twig template'),
'#default_value' => $facet->get('show_title'),
];
$empty_behavior_config = $facet->getEmptyBehavior();
$form['facet_settings']['empty_behavior'] = [
......@@ -708,6 +714,7 @@ class FacetForm extends EntityForm {
$facet->setUseHierarchy($form_state->getValue(['facet_settings', 'use_hierarchy']));
$facet->setExpandHierarchy($form_state->getValue(['facet_settings', 'expand_hierarchy']));
$facet->setEnableParentWhenChildGetsDisabled($form_state->getValue(['facet_settings', 'enable_parent_when_child_gets_disabled']));
$facet->set('show_title', $form_state->getValue(['facet_settings', 'show_title'], FALSE));
$facet->save();
drupal_set_message($this->t('Facet %name has been updated.', ['%name' => $facet->getName()]));
......
......@@ -857,6 +857,21 @@ class IntegrationTest extends FacetsTestBase {
$this->assertEquals('none', $current_cache['type']);
}
/**
* Tests that the configuration for showing a title works.
*/
public function testShowTitle() {
$this->createFacet("Llama", 'llama');
$this->drupalGet('search-api-test-fulltext');
$this->assertSession()->pageTextNotContains('Llama');
$this->drupalGet('admin/config/search/facets/llama/edit');
$this->drupalPostForm(NULL, ['facet_settings[show_title]' => TRUE], 'Save');
$this->assertSession()->checkboxChecked('Show title of facet');
$this->drupalGet('search-api-test-fulltext');
$this->assertSession()->responseContains('<h3>Llama</h3>');
$this->assertSession()->pageTextContains('Llama');
}
/**
* Configures empty behavior option to show a text on empty results.
*
......
......@@ -81,6 +81,7 @@ abstract class FacetResourceTestBase extends EntityResourceTestBase {
],
'query_operator' => NULL,
'show_only_one_result' => FALSE,
'show_title' => NULL,
'status' => TRUE,
'url_alias' => NULL,
'use_hierarchy' => FALSE,
......
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