/**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function processDecoratedDefinitions(array $decorated_plugin_definitions)
 {
     $processed_plugin_definitions = [];
     foreach ($decorated_plugin_definitions as $plugin_id => $decorated_plugin_definition) {
         $processed_plugin_definitions[$plugin_id] = $this->pluginType->ensureTypedPluginDefinition($decorated_plugin_definition);
     }
     return $processed_plugin_definitions;
 }
 /**
  * {@inheritdoc}
  *
  */
 public function setUp()
 {
     $this->defaultPluginResolver = $this->getMock(DefaultPluginResolverInterface::class);
     $this->pluginId = $this->randomMachineName();
     $this->selectablePluginManager = $this->getMock(PluginManagerInterface::class);
     $this->selectablePluginType = $this->getMock(PluginTypeInterface::class);
     $this->selectablePluginType->expects($this->any())->method('getPluginManager')->willReturn($this->selectablePluginManager);
     $this->selectedPlugin = $this->getMock(PluginInspectionInterface::class);
 }
 /**
  * @covers ::getDefinitions
  * @covers ::processDecoratedDefinitions
  */
 public function testGetDefinitions()
 {
     $decorated_plugin_id_a = $this->randomMachineName();
     $decorated_plugin_definition_a = ['id' => $decorated_plugin_id_a];
     $decorated_plugin_id_b = $this->randomMachineName();
     $decorated_plugin_definition_b = ['id' => $decorated_plugin_id_b];
     $decorated_plugin_definitions = [$decorated_plugin_id_a => $decorated_plugin_definition_a, $decorated_plugin_id_b => $decorated_plugin_definition_b];
     $this->pluginManager->expects($this->once())->method('getDefinitions')->willReturn($decorated_plugin_definitions);
     $typed_plugin_definition_a = $this->getMock(PluginDefinitionInterface::class);
     $typed_plugin_definition_b = $this->getMock(PluginDefinitionInterface::class);
     $map = [[$decorated_plugin_definition_a, $typed_plugin_definition_a], [$decorated_plugin_definition_b, $typed_plugin_definition_b]];
     $this->pluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnMap($map);
     $expected_plugin_definitions = [$decorated_plugin_id_a => $typed_plugin_definition_a, $decorated_plugin_id_b => $typed_plugin_definition_b];
     $this->assertSame($expected_plugin_definitions, $this->sut->getDefinitions());
 }
 /**
  * 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());
 }