RangeSlider.php in Range Slider 8
File
src/Element/RangeSlider.php
View source
<?php
namespace Drupal\range_slider\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\Range;
class RangeSlider extends Range {
public function getInfo() {
return [
'#process' => [
[
get_class($this),
'processRangeSlider',
],
],
'#data-orientation' => 'horizontal',
'#output' => FALSE,
'#output__field_prefix' => '',
'#output__field_suffix' => '',
] + parent::getInfo();
}
public static function preRenderRange($element) {
$element = parent::preRenderRange($element);
Element::setAttributes($element, [
'data-orientation',
]);
return $element;
}
public static function processRangeSlider(&$element, FormStateInterface $form_state, &$complete_form) {
if (isset($element['#output']) && in_array($element['#output'], self::getOutputTypes())) {
$element['#attached']['drupalSettings']['range_slider']['elements']['#' . $element['#id']]['output'] = $element['#output'];
}
if (isset($element['#output__field_prefix'])) {
$element['#attached']['drupalSettings']['range_slider']['elements']['#' . $element['#id']]['prefix'] = $element['#output__field_prefix'];
}
if (isset($element['#output__field_suffix'])) {
$element['#attached']['drupalSettings']['range_slider']['elements']['#' . $element['#id']]['suffix'] = $element['#output__field_suffix'];
}
$element['#attached']['library'][] = 'range_slider/element.rangeslider';
return $element;
}
private static function getOutputTypes() {
return [
'below',
'above',
'left',
'right',
];
}
}
Classes
Name |
Description |
RangeSlider |
Provides a slider for input of a number within a specific range. |