You are here

public static function Number::processElement in Price 3.0.x

Same name and namespace in other branches
  1. 8 src/Element/Number.php \Drupal\price\Element\Number::processElement()
  2. 3.x src/Element/Number.php \Drupal\price\Element\Number::processElement()
  3. 2.0.x src/Element/Number.php \Drupal\price\Element\Number::processElement()
  4. 2.x src/Element/Number.php \Drupal\price\Element\Number::processElement()

Builds the price_number form element.

Parameters

array $element: The initial price_number form element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

Return value

array The built price_number form element.

File

src/Element/Number.php, line 103

Class

Number
Provides a number form element with support for language-specific input.

Namespace

Drupal\price\Element

Code

public static function processElement(array $element, FormStateInterface $form_state, array &$complete_form) {

  // Add a sensible default AJAX event.
  if (isset($element['#ajax']) && !isset($element['#ajax']['event'])) {
    $element['#ajax']['event'] = 'blur';
  }

  // Provide an example to the end user so that they know which decimal
  // separator to use. This is the same pattern Drupal core uses.
  $number_formatter = \Drupal::service('price.number_formatter');
  $element['#placeholder'] = $number_formatter
    ->format('9.99');
  return $element;
}