Skip to content
Snippets Groups Projects
Commit a7825549 authored by Jonathan Sacksick's avatar Jonathan Sacksick
Browse files

Issue #3470982: Allow customizing the wrapper element and the display label for checkout panes

parent 3a646e45
No related branches found
No related tags found
1 merge request!324Issue #3470982: Allow customizing the wrapper element and the display label for checkout panes.
Pipeline #268415 passed
......@@ -112,9 +112,16 @@ commerce_checkout.commerce_checkout_pane.completion_message:
commerce_checkout_pane_configuration:
type: mapping
mapping:
display_label:
type: string
label: 'Display label'
translatable: true
step:
type: string
label: 'Step'
weight:
type: integer
label: 'Weight'
wrapper_element:
type: string
label: 'Wrapper element'
......@@ -110,6 +110,8 @@ abstract class CheckoutPaneBase extends PluginBase implements CheckoutPaneInterf
return [
'step' => $default_step,
'display_label' => NULL,
'wrapper_element' => $this->pluginDefinition['wrapper_element'],
'weight' => 10,
];
}
......@@ -118,13 +120,50 @@ abstract class CheckoutPaneBase extends PluginBase implements CheckoutPaneInterf
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
return '';
$summary = [];
$summary[] = $this->t('Display label: @display_label', [
'@display_label' => $this->getDisplayLabel(),
]);
$wrapper_element = $this->getWrapperElement();
if (!empty($wrapper_element)) {
$wrapper_element_options = $this->getWrapperElementOptions();
$summary[] = $this->t('Wrapper element: @wrapper_element', [
'@wrapper_element' => $wrapper_element_options[$wrapper_element] ?? $wrapper_element,
]);
}
return implode('<br>', $summary);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['display_label_override'] = [
'#title' => $this->t('Override the display label'),
'#type' => 'checkbox',
'#default_value' => !empty($this->configuration['display_label']),
];
$form['display_label'] = [
'#title' => $this->t('Display label'),
'#description' => $this->t('Specify the display label to use in checkout, overriding the default value set.'),
'#type' => 'textfield',
'#default_value' => $this->getDisplayLabel(),
'#states' => [
'visible' => [
':input[name="configuration[panes][' . $this->pluginId . '][configuration][display_label_override]"]' => ['checked' => TRUE],
],
],
];
if (isset($this->pluginDefinition['wrapper_element'])) {
$form['wrapper_element'] = [
'#title' => $this->t('Wrapper element'),
'#options' => $this->getWrapperElementOptions(),
'#type' => 'select',
'#default_value' => $this->getWrapperElement(),
];
}
return $form;
}
......@@ -136,7 +175,20 @@ abstract class CheckoutPaneBase extends PluginBase implements CheckoutPaneInterf
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
if (!$form_state->getErrors()) {
$values = $form_state->getValue($form['#parents']);
if (!empty($values['wrapper_element'])) {
$this->configuration['wrapper_element'] = $values['wrapper_element'];
}
if (!empty($values['display_label_override']) && !empty($values['display_label'])) {
$this->configuration['display_label'] = $values['display_label'];
}
else {
unset($this->configuration['display_label']);
}
}
}
/**
* {@inheritdoc}
......@@ -164,14 +216,14 @@ abstract class CheckoutPaneBase extends PluginBase implements CheckoutPaneInterf
* {@inheritdoc}
*/
public function getDisplayLabel() {
return $this->pluginDefinition['display_label'];
return $this->configuration['display_label'] ?? $this->pluginDefinition['display_label'];
}
/**
* {@inheritdoc}
*/
public function getWrapperElement() {
return $this->pluginDefinition['wrapper_element'];
return $this->configuration['wrapper_element'] ?? $this->pluginDefinition['wrapper_element'];
}
/**
......@@ -228,4 +280,18 @@ abstract class CheckoutPaneBase extends PluginBase implements CheckoutPaneInterf
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {}
/**
* Gets the "wrapper_element" allowed options.
*
* @return array
* The "wrapper_element" options.
*/
protected function getWrapperElementOptions(): array {
return [
'container' => $this->t('Container'),
'fieldset' => $this->t('Fieldset'),
'details' => $this->t('Details (Closed)'),
];
}
}
......@@ -30,6 +30,7 @@ class ContactInformation extends CheckoutPaneBase implements CheckoutPaneInterfa
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$parent_summary = parent::buildConfigurationSummary();
if (!empty($this->configuration['double_entry'])) {
$summary = $this->t('Require double entry of email: Yes');
}
......@@ -37,7 +38,7 @@ class ContactInformation extends CheckoutPaneBase implements CheckoutPaneInterfa
$summary = $this->t('Require double entry of email: No');
}
return $summary;
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
/**
......
......@@ -103,6 +103,7 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$parent_summary = parent::buildConfigurationSummary();
if (!empty($this->configuration['allow_guest_checkout'])) {
$summary = $this->t('Guest checkout: Allowed') . '<br>';
}
......@@ -118,7 +119,7 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container
$summary .= $this->t('Registration: Not allowed');
}
return $summary;
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
/**
......
......@@ -30,17 +30,20 @@ class OrderSummary extends CheckoutPaneBase implements CheckoutPaneInterface {
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$parent_summary = parent::buildConfigurationSummary();
if ($this->configuration['view']) {
$view_storage = $this->entityTypeManager->getStorage('view');
$view = $view_storage->load($this->configuration['view']);
if ($view) {
return $this->t('View: @view', ['@view' => $view->label()]);
$summary = $this->t('View: @view', ['@view' => $view->label()]);
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
return '';
return $parent_summary;
}
else {
return $this->t('View: Not used');
$summary = $this->t('View: Not used');
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
}
......
......@@ -76,10 +76,14 @@ class PaymentInformation extends PaymentCheckoutPaneBase {
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$parent_summary = parent::buildConfigurationSummary();
if (empty($this->configuration['require_payment_method'])) {
return $this->t('Customer payment methods will not be stored, if order balance is zero.');
$summary = $this->t('Customer payment methods will not be stored, if order balance is zero.');
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
return $this->t('Customer payment methods will always be stored, even if order balance is zero.');
$summary = $this->t('Customer payment methods will always be stored, even if order balance is zero.');
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
/**
......
......@@ -64,6 +64,7 @@ class PaymentProcess extends PaymentCheckoutPaneBase {
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$parent_summary = parent::buildConfigurationSummary();
if (!empty($this->configuration['capture'])) {
$summary = $this->t('Transaction mode: Authorize and capture');
}
......@@ -71,7 +72,7 @@ class PaymentProcess extends PaymentCheckoutPaneBase {
$summary = $this->t('Transaction mode: Authorize only');
}
return $summary;
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
/**
......
......@@ -49,6 +49,7 @@ class CouponRedemption extends CheckoutPaneBase {
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$parent_summary = parent::buildConfigurationSummary();
if ($this->configuration['allow_multiple']) {
$summary = $this->t('Allows multiple coupons: Yes');
}
......@@ -56,7 +57,7 @@ class CouponRedemption extends CheckoutPaneBase {
$summary = $this->t('Allows multiple coupons: No');
}
return $summary;
return $parent_summary ? implode('<br>', [$parent_summary, $summary]) : $summary;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment