Describe your bug or feature request.
I'm creating a custom module PocketPay. The basic part is to capture a value from user input. But I have tried for one week, just unable to capture the form value. Very frustrating. So I'm asking for any advice.
The below are the code of file PocketPayPane.php under custom/pocketpay/src/Plugin/Commerce/CheckoutPane and pocketpay.module under pocketpay directory. The form is set on Order_infomation page. When the checkbox is checked, nothing recorded in log. I tried use a text box to see whether that value can be captured. Also no.:
PocketPayPane.php
<?php
namespace Drupal\pocketpay\Plugin\Commerce\CheckoutPane;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a custom checkout pane for PocketPay.
*
* @CommerceCheckoutPane(
* id = "pocketpay_pane",
* label = @Translation("PocketPay Pane"),
* default_step = "order_information",
* )
*/
class PocketPayPane extends CheckoutPaneBase {
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form['field_pocket_pay'] = [
'#type' => 'checkbox',
'#title' => $this->t('Pocket Pay'),
'#default_value' => $form_state->getValue('field_pocket_pay'),
];
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
// Log the checkbox value.
\Drupal::logger('pocketpay')->notice('Checkbox value: @value', ['@value' => $form_state->getValue('field_pocket_pay')]);
// Save the custom boolean field value to the order.
$this->order->set('field_pocket_pay', $form_state->getValue('field_pocket_pay'));
$this->order->save();
}
}
pocketpay.module:
<?php
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_commerce_checkout_pane_info().
*/
function pocketpay_commerce_checkout_pane_info() {
$panes = [];
$panes['pocketpay_pane'] = [
'title' => t('PocketPay Pane'),
'page' => 'order_information',
'weight' => 0,
'status' => TRUE,
'region' => 'content',
'display_label' => 'above',
];
return $panes;
}
Thank you in advance for any help you can provide!