diff --git a/payment/js/payment.js b/payment/js/payment.js index 340d516..c2ca61d 100644 --- a/payment/js/payment.js +++ b/payment/js/payment.js @@ -5,9 +5,9 @@ Drupal.behaviors.paymentMethodConfigurationBasic = { attach: function (context) { var $context = $(context); - // Provide the vertical tab summaries. - $context.find('#edit-execute').drupalSetSummary(function (context) { - var payment_status_id = $('#edit-execute-status-id').val(); + var $details = $context.find('details[id$="-execute"]'); + $details.drupalSetSummary(function (context) { + var payment_status_id = $details.find('select[id$="-execute-execute-status-id"]').val(); return Drupal.t('Sets payments to %status.', { '%status' : drupalSettings.payment.payment_method_configuration_basic[payment_status_id] }); @@ -15,9 +15,11 @@ var i; var operations = ['capture', 'refund']; for (i in operations) { - $context.find('#edit-' + operations[i]).drupalSetSummary(function (context) { - if ($('#' + operations[i]).is(":checked")) { - var payment_status_id = $('#edit-' + operations[i] + '-status-id').val(); + var $details = $context.find('details[id$="-' + operations[i] + '"]'); + $details.drupalSetSummary(function (details) { + var $details = $(details); + if ($details.find('input[type=checkbox]').is(":checked")) { + var payment_status_id = $details.find('select[id$="-status-id"]').val(); return Drupal.t('Sets payments to %status.', { '%status' : drupalSettings.payment.payment_method_configuration_basic[payment_status_id] }); diff --git a/payment/src/Plugin/Payment/MethodConfiguration/Basic.php b/payment/src/Plugin/Payment/MethodConfiguration/Basic.php index 4d2325b..4ef5df9 100644 --- a/payment/src/Plugin/Payment/MethodConfiguration/Basic.php +++ b/payment/src/Plugin/Payment/MethodConfiguration/Basic.php @@ -199,7 +199,10 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl */ public function buildConfigurationForm(array $form, array &$form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['plugin_form']['#process'][] = array($this, 'processBuildConfigurationForm'); + $form['plugin_form'] = array( + '#process' => array(array($this, 'processBuildConfigurationForm')), + '#type' => 'container', + ); return $form; } @@ -208,7 +211,7 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl * Implements a form API #process callback. */ public function processBuildConfigurationForm(array &$element, array &$form_state, array &$form) { - $elements['brand_label'] = array( + $element['brand_label'] = array( '#default_value' => $this->getBrandLabel(), '#description' => $this->t('The label that payers will see when choosing a payment method. Defaults to the payment method label.'), '#title' => $this->t('Brand label'), @@ -218,7 +221,9 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl foreach ($this->paymentStatusManager->getDefinitions() as $definition) { $labels[$definition['id']] = (string) $definition['label']; } - $elements['workflow'] = array( + $workflow_group = implode('][', array_merge($element['#parents'], array('workflow'))); + $workflow_id = drupal_html_id('workflow'); + $element['workflow'] = array( '#attached' => array( 'js' => array( drupal_get_path('module', 'payment') . '/js/payment.js', @@ -232,15 +237,16 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl ), ), ), + '#id' => $workflow_id, '#type' => 'vertical_tabs', ); - $elements['execute'] = array( - '#group' => 'workflow', + $element['execute'] = array( + '#group' => $workflow_group, '#open' => TRUE, '#type' => 'details', '#title' => $this->t('Execution'), ); - $elements['execute']['execute_status_id'] = array( + $element['execute']['execute_status_id'] = array( '#default_value' => !$this->getExecuteStatusId() ?: $this->getExecuteStatusId(), '#description' => $this->t('The status to set payments to after being executed by this payment method.'), '#empty_value' => '', @@ -249,20 +255,20 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl '#title' => $this->t('Payment execution status'), '#type' => 'select', ); - $elements['capture'] = array( - '#group' => 'workflow', + $element['capture'] = array( + '#group' => $workflow_group, '#open' => TRUE, '#type' => 'details', '#title' => $this->t('Capture'), ); $capture_id = drupal_html_id('capture'); - $elements['capture']['capture'] = array( + $element['capture']['capture'] = array( '#id' => $capture_id, '#type' => 'checkbox', '#title' => $this->t('Add an additional capture step after payments have been executed.'), '#default_value' => $this->getCapture(), ); - $elements['capture']['capture_status_id'] = array( + $element['capture']['capture_status_id'] = array( '#description' => $this->t('The status to set payments to after being captured by this payment method.'), '#default_value' => $this->getCaptureStatusId(), '#options' => $this->paymentStatusManager->options(), @@ -278,19 +284,19 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl '#type' => 'select', ); $refund_id = drupal_html_id('refund'); - $elements['refund'] = array( - '#group' => 'workflow', + $element['refund'] = array( + '#group' => $workflow_group, '#open' => TRUE, '#type' => 'details', '#title' => $this->t('Refund'), ); - $elements['refund']['refund'] = array( + $element['refund']['refund'] = array( '#id' => $refund_id, '#type' => 'checkbox', '#title' => $this->t('Add an additional refund step after payments have been executed.'), '#default_value' => $this->getRefund(), ); - $elements['refund']['refund_status_id'] = array( + $element['refund']['refund_status_id'] = array( '#description' => $this->t('The status to set payments to after being refunded by this payment method.'), '#default_value' => $this->getRefundStatusId(), '#options' => $this->paymentStatusManager->options(), @@ -306,7 +312,7 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl '#type' => 'select', ); - return $elements; + return $element; } /** @@ -317,11 +323,11 @@ class Basic extends PaymentMethodConfigurationBase implements ContainerFactoryPl $parents = $form['plugin_form']['brand_label']['#parents']; array_pop($parents); $values = NestedArray::getValue($form_state['values'], $parents); - $this->setExecuteStatusId($values['execute_status_id']); - $this->setCapture($values['capture']); - $this->setCaptureStatusId($values['capture_status_id']); - $this->setRefund($values['refund']); - $this->setRefundStatusId($values['refund_status_id']); + $this->setExecuteStatusId($values['execute']['execute_status_id']); + $this->setCapture($values['capture']['capture']); + $this->setCaptureStatusId($values['capture']['capture_status_id']); + $this->setRefund($values['refund']['refund']); + $this->setRefundStatusId($values['refund']['refund_status_id']); $this->setBrandLabel($values['brand_label']); } diff --git a/payment/src/Tests/Controller/PaymentMethodWebTest.php b/payment/src/Tests/Controller/PaymentMethodWebTest.php index 13cde97..123283f 100644 --- a/payment/src/Tests/Controller/PaymentMethodWebTest.php +++ b/payment/src/Tests/Controller/PaymentMethodWebTest.php @@ -183,16 +183,18 @@ class PaymentMethodWebTest extends WebTestBase { $brand_label = $this->randomString(); $execute_status_id = 'payment_failed'; $capture_status_id = 'payment_success'; + $refund_status_id = 'payment_cancelled'; $id = strtolower($this->randomName()); $this->drupalPostForm(NULL, array( 'label' => $label, 'id' => $id, 'owner' => $user->label(), - 'plugin_form[brand_label]' => $brand_label, - 'plugin_form[execute_status_id]' => $execute_status_id, - 'plugin_form[capture]' => TRUE, - 'plugin_form[capture_status_id_wrapper][capture_status_id]' => $capture_status_id, - 'plugin_form[capture_status_id_wrapper][capture_status_id]' => $capture_status_id, + 'plugin_form[plugin_form][brand_label]' => $brand_label, + 'plugin_form[plugin_form][execute][execute_status_id]' => $execute_status_id, + 'plugin_form[plugin_form][capture][capture]' => TRUE, + 'plugin_form[plugin_form][capture][capture_status_id]' => $capture_status_id, + 'plugin_form[plugin_form][refund][refund]' => TRUE, + 'plugin_form[plugin_form][refund][refund_status_id]' => $refund_status_id, ), t('Save')); /** @var \Drupal\payment\Entity\PaymentMethodConfigurationInterface $payment_method */ $payment_method = entity_load('payment_method_configuration', $id);