function Range::valueCallback

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Range.php \Drupal\Core\Render\Element\Range::valueCallback()
  2. 8.9.x core/lib/Drupal/Core/Render/Element/Range.php \Drupal\Core\Render\Element\Range::valueCallback()
  3. 11.x core/lib/Drupal/Core/Render/Element/Range.php \Drupal\Core\Render\Element\Range::valueCallback()

Overrides FormElementBase::valueCallback

File

core/lib/Drupal/Core/Render/Element/Range.php, line 70

Class

Range
Provides a slider for input of a number within a specific range.

Namespace

Drupal\Core\Render\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
    if ($input === '') {
        $offset = ($element['#max'] - $element['#min']) / 2;
        // Round to the step.
        if (strtolower($element['#step']) != 'any') {
            $steps = round($offset / $element['#step']);
            $offset = $element['#step'] * $steps;
        }
        return $element['#min'] + $offset;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.