diff --git a/src/Controller/FacetSourceConfigController.php b/src/Controller/FacetSourceConfigController.php index 0b892bf..16e8f00 100644 --- a/src/Controller/FacetSourceConfigController.php +++ b/src/Controller/FacetSourceConfigController.php @@ -22,7 +22,7 @@ class FacetSourceConfigController extends ControllerBase { * The plugin id. * * @return array - * A renderable array containing the form + * A renderable array containing the form. */ public function facetSourceConfigForm($source_id) { /** @var \Drupal\facetapi\FacetSource\FacetSourcePluginManager $facet_source_plugin_manager */ @@ -31,8 +31,14 @@ class FacetSourceConfigController extends ControllerBase { try { $facet_source_plugin_manager->createInstance($source_id); } catch (PluginNotFoundException $e) { - // Return a renderable array with a short lifetime that represents the plugin not found. - return ['#markup' => 'Plugin not found.', '#cache' => ['max-age' => 5]]; + // Return a renderable array with a plugin not found message. We add a + // max-age to make sure that this message is not found indefinitely. + return [ + '#markup' => $this->t('Plugin not found.'), + '#cache' => [ + 'max-age' => 5, + ] + ]; } // Returns the render array of the FacetSourceConfigForm. diff --git a/src/Form/FacetSourceConfigForm.php b/src/Form/FacetSourceConfigForm.php index 198af19..491be51 100644 --- a/src/Form/FacetSourceConfigForm.php +++ b/src/Form/FacetSourceConfigForm.php @@ -38,7 +38,8 @@ class FacetSourceConfigForm extends ConfigFormBase { $overridden_filter_key_config = $config->get('overrides.' . $facet_source_id . '.filter_key'); $form['description'] = [ - '#markup' => $this->t('Saving this form will create a configuration override for this specific facet source. Not doing so will make sure that Facet API uses the default settings. This is an advanced feature and unless you are fully aware of why you\'re creating this configuration. With a default configuration of Facet API you can leave the default configuration.') + '#markup' => $this->t('Saving this form will create a configuration override for this specific facet source. + Unless you have to override facet source specific configuration, you can leave this to the default settings.') ]; $form['facet_source_id'] = [ @@ -53,7 +54,8 @@ class FacetSourceConfigForm extends ConfigFormBase { '#size' => 20, '#maxlength' => 255, '#default_value' => (!is_null($overridden_filter_key_config) ? $overridden_filter_key_config : $config->get('filter_key')), - '#description' => $this->t('They key used for filtering in the URL, defaults to f. You should change this to something else if you expect to have multiple facet sources on one page.'), + '#description' => $this->t('They key used for filtering in the URL, defaults to f. + You should change this to something else if you expect to have multiple facet sources on one page.'), ]; // The parent's form build method will add a save button. @@ -67,13 +69,11 @@ class FacetSourceConfigForm extends ConfigFormBase { // The parent's submitForm adds a message. parent::submitForm($form, $form_state); - $configKey = 'overrides.' . $form_state->getValue('facet_source_id') . '.'; - // When saving the config, make sure it's saved in the // 'overrides.facetsourceid.*' config name, so we can make sure that config // is possible to be overridden per facet source. $config = $this->config('facetapi.facet_source'); - $config->set($configKey. 'filter_key', $form_state->getValue('filter_key')); + $config->set('overrides.' . $form_state->getValue('facet_source_id') . '.filter_key', $form_state->getValue('filter_key')); $config->save(); } } diff --git a/src/Plugin/facetapi/processor/ExcludeSpecifiedItemsProcessor.php b/src/Plugin/facetapi/processor/ExcludeSpecifiedItemsProcessor.php index 9f62ae9..7f77ace 100644 --- a/src/Plugin/facetapi/processor/ExcludeSpecifiedItemsProcessor.php +++ b/src/Plugin/facetapi/processor/ExcludeSpecifiedItemsProcessor.php @@ -56,18 +56,18 @@ class ExcludeSpecifiedItemsProcessor extends ProcessorPluginBase implements Buil */ public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { $processors = $facet->getProcessors(); - $config = $processors[$this->getPluginId()]; + $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : null; $build['exclude'] = [ '#title' => $this->t('Exclude items'), '#type' => 'textfield', - '#default_value' => isset($config) ? $config->getConfiguration()['exclude'] : $this->defaultConfiguration()['exclude'], + '#default_value' => !is_null($config) ? $config->getConfiguration()['exclude'] : $this->defaultConfiguration()['exclude'], '#description' => $this->t("Comma separated list of titles or values that should be excluded, matching either an item's title or value."), ]; $build['regex'] = [ '#title' => $this->t('Regular expressions used'), '#type' => 'checkbox', - '#default_value' => isset($config) ? $config->getConfiguration()['regex'] : $this->defaultConfiguration()['regex'], + '#default_value' => !is_null($config) ? $config->getConfiguration()['regex'] : $this->defaultConfiguration()['regex'], '#description' => $this->t('Interpret each exclude list item as a regular expression pattern.
(Slashes are escaped automatically, patterns using a comma can be wrapped in "double quotes", and if such a pattern uses double quotes itself, just make them double-double-quotes ("")).'), ]; diff --git a/src/Plugin/facetapi/processor/MinimumCountProcessor.php b/src/Plugin/facetapi/processor/MinimumCountProcessor.php index 38b091b..7fca7a1 100644 --- a/src/Plugin/facetapi/processor/MinimumCountProcessor.php +++ b/src/Plugin/facetapi/processor/MinimumCountProcessor.php @@ -47,13 +47,13 @@ class MinimumCountProcessor extends ProcessorPluginBase implements BuildProcesso */ public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { $processors = $facet->getProcessors(); - $config = $processors[$this->getPluginId()]; + $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : null; $build['minimum_items'] = array( '#title' => $this->t('Minimum items'), '#type' => 'number', '#min' => 1, - '#default_value' => isset($config) ? $config->getConfiguration()['minimum_items'] : $this->defaultConfiguration()['minimum_items'], + '#default_value' => !is_null($config) ? $config->getConfiguration()['minimum_items'] : $this->defaultConfiguration()['minimum_items'], '#description' => $this->t('Hide block if the facet contains less than this number of results'), ); diff --git a/src/Processor/WidgetOrderPluginBase.php b/src/Processor/WidgetOrderPluginBase.php index c16351d..c170f72 100644 --- a/src/Processor/WidgetOrderPluginBase.php +++ b/src/Processor/WidgetOrderPluginBase.php @@ -19,7 +19,7 @@ abstract class WidgetOrderPluginBase extends ProcessorPluginBase implements Widg */ public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { $processors = $facet->getProcessors(); - $config = $processors[$this->getPluginId()]; + $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : null; $build['sort'] = [ '#type' => 'radios', @@ -28,7 +28,7 @@ abstract class WidgetOrderPluginBase extends ProcessorPluginBase implements Widg 'ASC' => $this->t('Ascending'), 'DESC' => $this->t('Descending'), ], - '#default_value' => isset($config) ? $config->getConfiguration()['sort'] : $this->defaultConfiguration()['sort'], + '#default_value' => !is_null($config) ? $config->getConfiguration()['sort'] : $this->defaultConfiguration()['sort'], ]; return $build;