class OrderFields in Commerce Checkout Order Fields 8
Exposes the "Checkout" form view mode during checkout.
Plugin annotation
@CommerceCheckoutPane(
id = "order_fields",
label = @Translation("Order fields"),
deriver = "\Drupal\commerce_checkout_order_fields\Plugin\Derivative\OrderFieldsPaneDeriver"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\commerce_checkout_order_fields\Plugin\Commerce\CheckoutPane\OrderFields
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of OrderFields
File
- src/
Plugin/ Commerce/ CheckoutPane/ OrderFields.php, line 18
Namespace
Drupal\commerce_checkout_order_fields\Plugin\Commerce\CheckoutPaneView source
class OrderFields extends CheckoutPaneBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'wrapper_element' => 'container',
'display_label' => $this->pluginDefinition['display_label'],
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$summary[] = $this
->t('<p>Wrapper element: :type</p>', [
':type' => ucfirst($this->configuration['wrapper_element']),
]);
$summary[] = $this
->t('<p>Display label: :label</p>', [
':label' => ucfirst($this->configuration['display_label']),
]);
return implode('', $summary);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['wrapper_element'] = [
'#type' => 'radios',
'#title' => $this
->t('Wrapper element'),
'#options' => [
'container' => $this
->t('Container'),
'fieldset' => $this
->t('Fieldset'),
],
'#required' => TRUE,
'#default_value' => $this->configuration['wrapper_element'],
];
$form['display_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Display label'),
'#description' => $this
->t('This is the display used when the wrapper element is a fieldset'),
'#default_value' => $this->configuration['display_label'],
'#states' => [
'visible' => [
':input[name="configuration[panes][' . $this
->getPluginId() . '][configuration][wrapper_element]"]' => [
'value' => 'fieldset',
],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
if (!$form_state
->getErrors()) {
$values = $form_state
->getValue($form['#parents']);
$this->configuration['wrapper_element'] = $values['wrapper_element'];
$this->configuration['display_label'] = $values['display_label'];
}
}
/**
* {@inheritdoc}
*/
public function getWrapperElement() {
return $this->configuration['wrapper_element'];
}
/**
* {@inheritdoc}
*/
public function getDisplayLabel() {
return $this->configuration['display_label'];
}
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$this
->getFormDisplay()
->buildForm($this->order, $pane_form, $form_state);
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$this
->getFormDisplay()
->extractFormValues($this->order, $pane_form, $form_state);
$this
->getFormDisplay()
->validateFormValues($this->order, $pane_form, $form_state);
parent::validatePaneForm($pane_form, $form_state, $complete_form);
}
/**
* {@inheritdoc}
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$this
->getFormDisplay()
->extractFormValues($this->order, $pane_form, $form_state);
parent::submitPaneForm($pane_form, $form_state, $complete_form);
}
/**
* {@inheritdoc}
*/
public function buildPaneSummary() {
$build = [];
// Get the form display to discover which fields should be rendered for the
// summary. View them using the same display mode ID as the form display
// mode. If it exists, then Drupal will use it. If not, the default display
// mode will be used.
$view_builder = $this->entityTypeManager
->getViewBuilder('commerce_order');
$form_display = $this
->getFormDisplay();
foreach (array_keys($form_display
->getComponents()) as $component_name) {
if (!$this->order
->get($component_name)
->isEmpty()) {
$build[$component_name] = $view_builder
->viewField($this->order
->get($component_name), $this
->getDerivativeId());
}
}
return $build;
}
/**
* Gets the form.
*
* @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
* The form display.
*/
private function getFormDisplay() {
$display = EntityFormDisplay::collectRenderDisplay($this->order, $this
->getDerivativeId());
$display
->removeComponent('coupons');
return $display;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CheckoutPaneBase:: |
protected | property | The parent checkout flow. | |
CheckoutPaneBase:: |
protected | property | The entity type manager. | |
CheckoutPaneBase:: |
protected | property | The current order. | |
CheckoutPaneBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
CheckoutPaneBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
7 |
CheckoutPaneBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane label. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane step ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane weight. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Determines whether the pane is visible. Overrides CheckoutPaneInterface:: |
4 |
CheckoutPaneBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the current order. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the pane step ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the pane weight. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
CheckoutPaneBase:: |
public | function |
Constructs a new CheckoutPaneBase object. Overrides PluginBase:: |
6 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
OrderFields:: |
public | function |
Form constructor. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Builds a summary of the pane configuration. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Builds the pane form. Overrides CheckoutPaneInterface:: |
|
OrderFields:: |
public | function |
Builds a summary of the pane values. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Gets default configuration for this plugin. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Gets the pane display label. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
private | function | Gets the form. | |
OrderFields:: |
public | function |
Gets the pane wrapper element. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Form submission handler. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Handles the submission of an pane form. Overrides CheckoutPaneBase:: |
|
OrderFields:: |
public | function |
Validates the pane form. Overrides CheckoutPaneBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |