/** * {@inheritdoc} */ public function execute(PaymentInterface $payment = NULL) { if ($payment) { $status = $this->paymentStatusType->getPluginManager()->createInstance($this->configuration['payment_status_plugin_id']); $payment->setPaymentStatus($status); } }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $allowed_selectable_plugin_ids = NULL, $plugin_id = NULL, $tree = FALSE) { if ($form_state->has('plugin_selector')) { $plugin_selector = $form_state->get('plugin_selector'); } else { $selectable_plugin_discovery = new LimitedPluginDiscoveryDecorator($this->selectablePluginType->getPluginManager()); $selectable_plugin_discovery->setDiscoveryLimit(explode(',', $allowed_selectable_plugin_ids)); $selectable_plugin_manager = new PluginManagerDecorator($this->selectablePluginType->getPluginManager(), $selectable_plugin_discovery); $plugin_selector = $this->pluginSelectorManager->createInstance($plugin_id); $plugin_selector->setSelectablePluginType($this->selectablePluginType); $plugin_selector->setSelectablePluginDiscovery($selectable_plugin_manager); $plugin_selector->setSelectablePluginFactory($selectable_plugin_manager); $plugin_selector->setRequired(); $form_state->set('plugin_selector', $plugin_selector); } $form['plugin'] = $plugin_selector->buildSelectorForm([], $form_state); // Nest the selector in a tree if that's required. if ($tree) { $form['tree'] = array('#tree' => TRUE); $form['tree']['plugin'] = $form['plugin']; unset($form['plugin']); } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Submit')); return $form; }
/** * Gets the payment method manager. * * @return \Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface */ protected function getPaymentMethodManager() { $config = $this->config('payment_form.payment_type'); $limit_allowed_plugins = $config->get('limit_allowed_plugins'); $payment_method_discovery = $this->paymentMethodType->getPluginManager(); if ($limit_allowed_plugins) { $allowed_plugin_ids = $config->get('allowed_plugin_ids'); $payment_method_discovery = new LimitedPluginDiscoveryDecorator($payment_method_discovery); $payment_method_discovery->setDiscoveryLimit($allowed_plugin_ids); } $payment_method_manager = new PaymentExecutionPaymentMethodManager($this->getEntity(), $this->currentUser, $this->paymentMethodType->getPluginManager(), $payment_method_discovery); return $payment_method_manager; }
/** * Gets the payment status selector. * * @param \Drupal\Core\Form\FormStateInterface $form_state * @param string $type * @param string $default_plugin_id * * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface */ protected function getPaymentStatusSelector(FormStateInterface $form_state, $type, $default_plugin_id) { $key = 'payment_status_selector_' . $type; if ($form_state->has($key)) { $plugin_selector = $form_state->get($key); } else { $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list'); $plugin_selector->setSelectablePluginType($this->paymentStatusType); $plugin_selector->setRequired(TRUE); $plugin_selector->setCollectPluginConfiguration(FALSE); $plugin_selector->setSelectedPlugin($this->paymentStatusType->getPluginManager()->createInstance($default_plugin_id)); $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) { $config = $this->config('payment_form.payment_type'); if ($form_state->has('plugin_selector')) { $plugin_selector = $form_state->get('plugin_selector'); } else { $plugin_selector_manager = $this->pluginSelectorType->getPluginManager(); $plugin_selector = $plugin_selector_manager->createInstance('payment_radios'); $plugin_selector->setSelectablePluginType($this->pluginSelectorType); $plugin_selector->setLabel($this->t('Payment method selector')); $plugin_selector->setRequired(); $plugin_selector->setSelectedPlugin($plugin_selector_manager->createInstance($config->get('plugin_selector_id'))); $form_state->set('plugin_selector', $plugin_selector); } return $plugin_selector; }
/** * Gets the plugin selector. * * @param mixed[] $element * @param \Drupal\Core\Form\FormStateInterface $form_state * * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface */ protected function getPluginSelector(array $element, FormStateInterface $form_state) { $key = 'payment_reference.element.payment_reference.plugin_selector.' . $element['#name']; if (!$form_state->has($key)) { $plugin_selector = $this->pluginSelectorManager->createInstance($element['#plugin_selector_id']); $payment_method_discovery = $this->paymentMethodType->getPluginManager(); if (!is_null($element['#limit_allowed_plugin_ids'])) { $payment_method_discovery = (new LimitedPluginDiscoveryDecorator($payment_method_discovery))->setDiscoveryLimit($element['#limit_allowed_plugin_ids']); } $payment_method_manager = new PaymentExecutionPaymentMethodManager($this->getPayment($element, $form_state), $this->currentUser, $this->paymentMethodType->getPluginManager(), $payment_method_discovery); $plugin_selector->setSelectablePluginType($this->paymentMethodType); $plugin_selector->setSelectablePluginDiscovery($payment_method_manager); $plugin_selector->setSelectablePluginFactory($payment_method_manager); $plugin_selector->setRequired($element['#required']); $form_state->set($key, $plugin_selector); } return $form_state->get($key); }
/** * {@inheritdoc} */ public function setSelectablePluginType(PluginTypeInterface $plugin_type) { $this->selectablePluginDiscovery = new TypedDefinitionEnsuringPluginDiscoveryDecorator($plugin_type); $this->selectablePluginFactory = $plugin_type->getPluginManager(); $this->selectablePluginType = $plugin_type; $default_plugin = $this->defaultPluginResolver->createDefaultPluginInstance($plugin_type); if ($default_plugin) { $this->setSelectedPlugin($default_plugin); } return $this; }
/** * Gets the entity reference selection manager. * * @return \Drupal\Component\Plugin\PluginManagerInterface */ protected function getPluginManager() { return new EntityReferenceSelectionManagerDecorator($this->targetEntityTypeId, $this->entityReferenceSelectionPluginType->getPluginManager()); }
/** * Constructs a new instance. * * @param \Drupal\plugin\PluginType\PluginTypeInterface $plugin_type * The plugin type of which to decorate definitions. * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface|NULL $decorated_discovery * The decorated discovery, or NULL to use the plugin type's default * discovery. */ public function __construct(PluginTypeInterface $plugin_type, DiscoveryInterface $decorated_discovery = NULL) { parent::__construct($decorated_discovery ?: $plugin_type->getPluginManager()); $this->pluginType = $plugin_type; }