/**
  * {@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;
 }
 /**
  * @covers ::getDefinitions
  * @covers ::processDecoratedDefinitions
  * @covers ::setDiscoveryLimit
  * @covers ::resetDiscoveryLimit
  */
 public function testGetDefinitionsWithoutAllowedPlugins()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_definition_a = ['id' => $plugin_id_a];
     $plugin_id_b = $this->randomMachineName();
     $plugin_definition_b = ['id' => $plugin_id_b];
     $plugin_id_c = $this->randomMachineName();
     $plugin_definition_c = ['id' => $plugin_id_c];
     $plugin_definitions = [$plugin_id_a => $plugin_definition_a, $plugin_id_b => $plugin_definition_b, $plugin_id_c => $plugin_definition_c];
     $this->pluginManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_definitions);
     $this->sut->setDiscoveryLimit([]);
     $this->assertEquals([], $this->sut->getDefinitions());
 }
 /**
  * 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;
 }
 /**
  * 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;
 }