You are here

class RangeSliderWidget in Facets 8

The range slider widget.

Plugin annotation


@FacetsWidget(
  id = "range_slider",
  label = @Translation("Range slider"),
  description = @Translation("A widget that shows a range slider."),
)

Hierarchy

Expanded class hierarchy of RangeSliderWidget

1 file declares its use of RangeSliderWidget
RangeSliderWidgetTest.php in modules/facets_range_widget/tests/src/Unit/Plugin/widget/RangeSliderWidgetTest.php

File

modules/facets_range_widget/src/Plugin/facets/widget/RangeSliderWidget.php, line 16

Namespace

Drupal\facets_range_widget\Plugin\facets\widget
View source
class RangeSliderWidget extends SliderWidget {

  /**
   * {@inheritdoc}
   */
  public function build(FacetInterface $facet) {
    $build = parent::build($facet);
    if (empty($facet
      ->getResults())) {
      return $build;
    }
    $active = $facet
      ->getActiveItems();
    $facet_settings =& $build['#attached']['drupalSettings']['facets']['sliders'][$facet
      ->id()];
    $facet_settings['range'] = TRUE;
    $facet_settings['url'] = reset($facet_settings['urls']);
    unset($facet_settings['value']);
    unset($facet_settings['urls']);
    $min = $facet_settings['min'];
    $max = $facet_settings['max'];
    $facet_settings['values'] = [
      isset($active[0][0]) ? (double) $active[0][0] : $min,
      isset($active[0][1]) ? (double) $active[0][1] : $max,
    ];
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function isPropertyRequired($name, $type) {
    if ($name === 'range_slider' && $type === 'processors') {
      return TRUE;
    }
    if ($name === 'show_only_one_result' && $type === 'settings') {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getQueryType() {
    return 'range';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
RangeSliderWidget::build public function Builds the facet widget for rendering. Overrides SliderWidget::build
RangeSliderWidget::getQueryType public function Picks the preferred query type for this widget. Overrides WidgetPluginBase::getQueryType
RangeSliderWidget::isPropertyRequired public function Checks is a specific property is required for this widget. Overrides SliderWidget::isPropertyRequired
SliderWidget::buildConfigurationForm public function Provides a configuration form for this widget. Overrides WidgetPluginBase::buildConfigurationForm
SliderWidget::defaultConfiguration public function Gets default configuration for this plugin. Overrides WidgetPluginBase::defaultConfiguration
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WidgetPluginBase::$facet protected property The facet the widget is being built for.
WidgetPluginBase::$showNumbers protected property Show the amount of results next to the result.
WidgetPluginBase::buildListItems protected function Builds a renderable array of result items. 1
WidgetPluginBase::buildResultItem protected function Builds a facet result item.
WidgetPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
WidgetPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
WidgetPluginBase::getFacetItemListThemeHook protected function Provides a full array of possible theme functions to try for a given hook.
WidgetPluginBase::prepareLink protected function Returns the text or link for an item.
WidgetPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
WidgetPluginBase::supportsFacet public function Checks if the facet is supported by this processor. Overrides WidgetPluginInterface::supportsFacet 1
WidgetPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct