function ImageButton::valueCallback

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

Overrides FormElementBase::valueCallback

File

core/lib/Drupal/Core/Render/Element/ImageButton.php, line 33

Class

ImageButton
Provides a form element for a submit button with an image.

Namespace

Drupal\Core\Render\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
  if ($input !== FALSE) {
    if (!empty($input)) {
      // If we're dealing with Mozilla or Opera, we're lucky. It will
      // return a proper value, and we can get on with things.
      return $element['#return_value'];
    }
    else {
      // Unfortunately, in IE we never get back a proper value for THIS
      // form element. Instead, we get back two split values: one for the
      // X and one for the Y coordinates on which the user clicked the
      // button. We'll find this element in the #post data, and search
      // in the same spot for its name, with '_x'.
      $input = $form_state->getUserInput();
      foreach (explode('[', $element['#name']) as $element_name) {
        // Chop off the ] that may exist.
        if (str_ends_with($element_name, ']')) {
          $element_name = substr($element_name, 0, -1);
        }
        if (!isset($input[$element_name])) {
          if (isset($input[$element_name . '_x'])) {
            return $element['#return_value'];
          }
          return NULL;
        }
        $input = $input[$element_name];
      }
      return $element['#return_value'];
    }
  }
}

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