/** * {@inheritdoc} */ public function build(FacetInterface $facet, array $results) { $processors = $facet->getProcessors(); $config = $processors[$this->getPluginId()]; // This should load the facet's config to find the ordering direction. return $this->sortResults($results, $config->getConfiguration()['sort']); }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { $processors = $facet->getProcessors(); $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL; $build['exclude'] = ['#title' => $this->t('Exclude items'), '#type' => 'textfield', '#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' => !is_null($config) ? $config->getConfiguration()['regex'] : $this->defaultConfiguration()['regex'], '#description' => $this->t('Interpret each exclude list item as a regular expression pattern.<br /><small>(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 (""))</small>.')]; return $build; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { $processors = $facet->getProcessors(); $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL; $build['minimum_items'] = array('#title' => $this->t('Minimum items'), '#type' => 'number', '#min' => 1, '#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.')); $max_default_value = !is_null($config) ? $config->getConfiguration()['maximum_items'] : $this->defaultConfiguration()['maximum_items']; $build['maximum_items'] = array('#title' => $this->t('Maximum items'), '#type' => 'number', '#min' => 1, '#default_value' => $max_default_value ? $max_default_value : '', '#description' => $this->t('Hide block if the facet contains more than this number of results.')); return $build; }
/** * {@inheritdoc} */ public function build(FacetInterface $facet, array $results) { $processors = $facet->getProcessors(); $config = $processors[$this->getPluginId()]; $char = $config->getConfiguration()['character']; /** @var \Drupal\facets\Result\ResultInterface $result */ foreach ($results as $id => $result) { if (strpos(strtolower($result->getDisplayValue()), $char) === 0) { unset($results[$id]); } } return $results; }