You are here

public static function PaymentReferenceBase::valueCallback in Payment 8.2

Determines how user input is mapped to an element's #value property.

Parameters

array $element: An associative array containing the properties of the element.

mixed $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.

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

Return value

mixed The value to assign to the element.

Overrides FormElement::valueCallback

File

src/Element/PaymentReferenceBase.php, line 604

Class

PaymentReferenceBase
Provides a base for payment reference elements.

Namespace

Drupal\payment\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {

  // Ignore $input, because the element's value does not come from submitted
  // form values, but from the payment queue.
  if ($element['#default_value']) {
    return $element['#default_value'];
  }
  else {

    /** @var \Drupal\Component\Plugin\PluginManagerInterface $element_info_manager */
    $element_info_manager = \Drupal::service('plugin.manager.element_info');

    /** @var \Drupal\payment\Element\PaymentReferenceBase $element_plugin */
    $element_plugin = $element_info_manager
      ->createInstance($element['#type']);
    $payment_ids = $element_plugin
      ->getPaymentQueue()
      ->loadPaymentIds($element['#queue_category_id'], $element['#queue_owner_id']);
    return $payment_ids ? (int) reset($payment_ids) : NULL;
  }
}