View source
<?php
namespace Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class CheckoutPaneBase extends PluginBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface {
protected $entityTypeManager;
protected $checkoutFlow;
protected $order;
public function __construct(array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->checkoutFlow = $checkout_flow;
$this->order = $checkout_flow
->getOrder();
$this
->setConfiguration($configuration);
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $checkout_flow, $container
->get('entity_type.manager'));
}
public function calculateDependencies() {
return [
'module' => [
$this->pluginDefinition['provider'],
],
];
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
public function defaultConfiguration() {
$available_steps = array_keys($this->checkoutFlow
->getSteps());
$available_steps[] = '_sidebar';
$default_step = $this->pluginDefinition['default_step'];
if (!$default_step || !in_array($default_step, $available_steps)) {
$default_step = '_disabled';
}
return [
'step' => $default_step,
'weight' => 10,
];
}
public function buildConfigurationSummary() {
return '';
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function setOrder(OrderInterface $order) {
$this->order = $order;
return $this;
}
public function getId() {
return $this->pluginId;
}
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getDisplayLabel() {
return $this->pluginDefinition['display_label'];
}
public function getWrapperElement() {
return $this->pluginDefinition['wrapper_element'];
}
public function getStepId() {
return $this->configuration['step'];
}
public function setStepId($step_id) {
$this->configuration['step'] = $step_id;
}
public function getWeight() {
return $this->configuration['weight'];
}
public function setWeight($weight) {
$this->configuration['weight'] = $weight;
}
public function isVisible() {
return TRUE;
}
public function buildPaneSummary() {
return [];
}
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
}
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
}
}