You are here

protected function PaymentStatusForm::getPluginSelector in Payment 8.2

Gets the plugin selector.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

\Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface

1 call to PaymentStatusForm::getPluginSelector()
PaymentStatusForm::submitForm in src/Entity/Payment/PaymentStatusForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…

File

src/Entity/Payment/PaymentStatusForm.php, line 142

Class

PaymentStatusForm
Provides the payment status update form.

Namespace

Drupal\payment\Entity\Payment

Code

protected function getPluginSelector(FormStateInterface $form_state) {
  if ($form_state
    ->has('plugin_selector')) {
    $plugin_selector = $form_state
      ->get('plugin_selector');
  }
  else {

    /** @var \Drupal\payment\Entity\PaymentInterface $payment */
    $payment = $this
      ->getEntity();
    $payment_method = $payment
      ->getPaymentMethod();
    $payment_status_discovery = new LimitedPluginDiscoveryDecorator($this->paymentStatusPluginType
      ->getPluginManager());
    if ($payment_method instanceof PaymentMethodUpdatePaymentStatusInterface) {
      $payment_status_discovery
        ->setDiscoveryLimit($payment_method
        ->getSettablePaymentStatuses($this->currentUser, $payment));
    }
    $payment_status_manager = new PaymentAwarePluginManagerDecorator($payment, $this->paymentStatusPluginType
      ->getPluginManager(), $payment_status_discovery);
    $plugin_selector = $this->pluginSelectorManager
      ->createInstance('payment_select_list');
    $plugin_selector
      ->setSelectablePluginType($this->paymentStatusPluginType, $payment_status_manager);
    $plugin_selector
      ->setRequired();
    $plugin_selector
      ->setLabel($this
      ->t('Payment status'));
    $form_state
      ->set('plugin_selector', $plugin_selector);
  }
  return $plugin_selector;
}