/** * Gets the parent payment status selector. * * @param \Drupal\Core\Form\FormStateInterface $form_state * * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface */ protected function getParentPaymentStatusSelector(FormStateInterface $form_state) { $key = 'parent_payment_status_selector'; if ($form_state->has($key)) { $plugin_selector = $form_state->get($key); } else { $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list'); $plugin_selector->setSelectablePluginType($this->pluginTypeManager->getPluginType('payment_status')); $plugin_selector->setCollectPluginConfiguration(FALSE); $plugin_selector->setLabel($this->t('Parent status')); $form_state->set($key, $plugin_selector); } return $plugin_selector; }
/** * Gets the plugin selector. * * @param \Drupal\Core\Form\FormStateInterface $form_state * * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface */ 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(); $plugin_type = $this->pluginTypeManager->getPluginType('payment_method'); $payment_method = $payment->getPaymentMethod(); $payment_status_discovery = new LimitedPluginDiscoveryDecorator($plugin_type->getPluginManager()); if ($payment_method instanceof PaymentMethodUpdatePaymentStatusInterface) { $payment_status_discovery->setDiscoveryLimit($payment_method->getSettablePaymentStatuses($this->currentUser, $payment)); } $payment_status_manager = new PaymentAwarePluginManagerDecorator($payment, $plugin_type->getPluginManager(), $payment_status_discovery); $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list'); $plugin_selector->setSelectablePluginType($plugin_type, $payment_status_manager); $plugin_selector->setRequired(); $plugin_selector->setLabel($this->t('Payment status')); $form_state->set('plugin_selector', $plugin_selector); } return $plugin_selector; }