You are here

class Slider in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/pagerer/Slider.php \Drupal\pagerer\Plugin\pagerer\Slider

Pager style using a jQuery slider.

Page navigation is managed via javascript.

Plugin annotation


@PagererStyle(
  id = "slider",
  title = @Translation("Slider pager"),
  short_title = @Translation("Slider"),
  help = @Translation("Pager style using a jQuery slider to select the page."),
  style_type = "base"
)

Hierarchy

Expanded class hierarchy of Slider

1 string reference to 'Slider'
Slider::buildConfigurationForm in src/Plugin/pagerer/Slider.php
Form constructor.

File

src/Plugin/pagerer/Slider.php, line 20

Namespace

Drupal\pagerer\Plugin\pagerer
View source
class Slider extends PagererStyleBase {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $config = parent::buildConfigurationForm($form, $form_state);
    unset($config['separators_container']);
    $config['plugin'] = [
      '#type' => 'details',
      '#title' => $this
        ->t("Slider"),
      '#description' => $this
        ->t("Slider options."),
    ];
    $config['plugin']['slider_width'] = [
      '#type' => 'number',
      '#title' => $this
        ->t("Width"),
      '#field_suffix' => $this
        ->t("em"),
      '#default_value' => $this->configuration['slider_width'],
      '#description' => $this
        ->t("The width of the slider bar. Expressed in 'em' for CSS styling. Leave blank to default to CSS settings."),
      '#required' => FALSE,
      '#size' => 3,
      '#maxlength' => 3,
      '#min' => 1,
    ];
    $options = [
      'tickmark',
      'timeout',
      'auto',
    ];
    $options = array_combine($options, $options);
    $config['plugin']['slider_action'] = [
      '#type' => 'select',
      '#title' => $this
        ->t("Action confirmation method"),
      '#options' => $options,
      '#default_value' => $this->configuration['slider_action'],
      '#description' => $this
        ->t("Select how the page relocation should be triggered after it has been selected through the slider. Options are: 'tickmark' (page relocation only occurs after user clicks a tickmark on the slider handle), 'timeout' (page relocation occurs after a grace time has elapsed), 'auto' (the timeout method is automatically selected based on the accuracy of the slider)."),
      '#required' => TRUE,
    ];
    $config['plugin']['slider_action_timeout'] = [
      '#type' => 'number',
      '#title' => $this
        ->t("Confirmation timeout"),
      '#default_value' => $this->configuration['slider_action_timeout'],
      '#description' => $this
        ->t("The grace time (in milliseconds) to wait before the page is relocated, in case 'timeout' confirmation method is selected. '0' will trigger relocation immediately."),
      '#size' => 5,
      '#maxlength' => 5,
      '#required' => TRUE,
      '#min' => 0,
    ];
    $options = [
      'yes',
      'no',
      'auto',
    ];
    $options = array_combine($options, $options);
    $config['plugin']['slider_navigation_icons'] = [
      '#type' => 'select',
      '#title' => $this
        ->t("Display navigation icons"),
      '#options' => $options,
      '#default_value' => $this->configuration['slider_navigation_icons'],
      '#description' => $this
        ->t("Select whether to display +/- navigation icons on the sides of the slider. Options are 'yes', 'no', 'auto' (the icons are automatically displayed based on the accuracy of the slider)."),
      '#required' => TRUE,
    ];
    return $config;
  }

  /**
   * Return the pager render array.
   *
   * @return array
   *   render array.
   */
  protected function buildPagerItems() {

    // Prepares state.
    $state_settings = [
      'action' => $this
        ->getOption('slider_action'),
      'timeout' => $this
        ->getOption('slider_action_timeout'),
      'icons' => $this
        ->getOption('slider_navigation_icons'),
      'tickmarkTitle' => $this
        ->getDisplayTag('slider_tickmark_title'),
    ];
    if ($slider_width = $this
      ->getOption('slider_width')) {
      $state_settings['sliderWidth'] = $slider_width;
    }
    $pagerer_widget_id = $this
      ->prepareJsState($state_settings);

    // Add pager items.
    $items = [];
    if ($this
      ->getOption('slider_navigation_icons') != 'no') {
      $items[] = [
        'widget' => [
          '#theme' => 'pagerer_slider_icon',
          '#icon' => 'circle-minus',
        ],
      ];
    }
    $items[] = [
      'widget' => [
        '#theme' => 'pagerer_slider',
        '#id' => $pagerer_widget_id,
        '#title' => $this
          ->getDisplayTag('slider_title'),
        '#attached' => [
          'drupalSettings' => [
            'pagerer' => [
              'state' => [
                $pagerer_widget_id => $state_settings,
              ],
            ],
          ],
        ],
      ],
    ];
    if ($this
      ->getOption('slider_navigation_icons') != 'no') {
      $items[] = [
        'widget' => [
          '#theme' => 'pagerer_slider_icon',
          '#icon' => 'circle-plus',
        ],
      ];
    }
    return $items;
  }

}

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.
PagererStyleBase::$configFactory protected property The config factory.
PagererStyleBase::$pager protected property The Pagerer pager object.
PagererStyleBase::$pagererPreset protected property The PagererPreset object being configured.
PagererStyleBase::$pagererPresetPane protected property The PagererPreset pane being configured.
PagererStyleBase::$parameters protected property Query parameters as requested by the theme call.
PagererStyleBase::$typedConfigManager protected property The config type plugins manager.
PagererStyleBase::buildEmptyPager protected function Render a 'no pages to display' text. 1
PagererStyleBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PagererStyleBase::getDisplayTag protected function Returns a translated textual element for pages/items/item ranges.
PagererStyleBase::getNavigationItem protected function Gets a link/button item to first/previous/next/last link.
PagererStyleBase::getOption protected function Returns a configuration element.
PagererStyleBase::getPageItem protected function Gets a 'page' item in the pager.
PagererStyleBase::getTag protected function Returns a translated textual element from the configuration.
PagererStyleBase::prepareJsState protected function Prepares input parameters for a JS enabled pager widget.
PagererStyleBase::preprocess public function Prepares to render the pager. Overrides PagererStyleInterface::preprocess
PagererStyleBase::setConfigurationContext public function Sets the current PagererPreset and pane being configured.
PagererStyleBase::setPager public function Sets the Pagerer pager to be rendered. Overrides PagererStyleInterface::setPager
PagererStyleBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
PagererStyleBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
PagererStyleBase::__construct public function Constructs a \Drupal\pagerer\Plugin\pagerer\PagererStyleBase object. Overrides PluginBase::__construct
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.
Slider::buildConfigurationForm public function Form constructor. Overrides PagererStyleBase::buildConfigurationForm
Slider::buildPagerItems protected function Return the pager render array.
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.