Problem/Motivation
If the payment method settings_form extends from ConfigForm, in admin/store/config/payment click the Settings will cause this problem:
The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Argument 1 passed to Drupal\Core\Form\ConfigFormBase::__construct() must implement interface Drupal\Core\Config\ConfigFactoryInterface, none given, called in /home/jian/src/drupal8/modules/ubercart/payment/uc_payment/src/PaymentMethodPluginBase.php on line 104 and defined in Drupal\Core\Form\ConfigFormBase->__construct() (line 25 of core/lib/Drupal/Core/Form/ConfigFormBase.php).
Drupal\Core\Form\ConfigFormBase->__construct()
Drupal\uc_payment\PaymentMethodPluginBase->getSettingsForm()
Drupal\uc_payment\Form\PaymentMethodSettingsForm->buildForm(Array, Object, 'paypal_ec')
call_user_func_array(Array, Array)
Drupal\Core\Form\FormBuilder->retrieveForm('uc_payment_method_settings_form', Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)
Proposed resolution
PaymentMethodPlugin should support settings_form which extends from ConfigForm.
Comments
Comment #2
jian he commentedComment #3
tr commentedCurrently it is designed to support forms which extend FormBase. These settings forms are embedded in another ConfigForm. If the settings forms were also ConfigForms then there would be two "Save configuration" buttons added. The type of form used for settings is necessarily restricted because we are explicitly invoking the settings form methods from withing the parent form, which we can only do if we know ALL the methods we need to invoke. Can't easily have a mixture of form types.
So right now this is "as designed". It's not the best architecture, and needs to be revisted to take advantage of the additional features added to D8 recently, but it works as it is. If you follow the examples in uc_payment_pack you will be able to make your payment method work.
This is also one of the reasons I want to just spend the time on Payment integration - Payment already has a complex architecture which makes things like settings forms cleaner, I would rather not have to re-invent this within Ubercart.
Comment #4
jian he commentedI see.
Comment #5
jian he commentedYes it seems the architecture for payment settings_form need polish.
Comment #6
longwave#2620956: Convert payment methods and gateways into configuration entities takes a different approach and adds ConfigurablePluginInterface and PluginFormInterface to the PaymentMethodPluginInterface, which lets the payment method configuration be stored inside an entity rather than as standalone configuration, and means the settings form will live inside the plugin class itself.
Comment #7
jian he commentedlongwave, that sounds great, hopes the convert can be finished soon :)
Comment #8
longwave#2620956: Convert payment methods and gateways into configuration entities has been committed and payment method settings forms now use PluginFormInterface.