View source
<?php
namespace Drupal\commerce_checkout;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class CheckoutPaneManager extends DefaultPluginManager {
protected $defaults = [
'id' => '',
'label' => '',
'admin_label' => '',
'default_step' => '_disabled',
'wrapper_element' => 'container',
];
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Commerce/CheckoutPane', $namespaces, $module_handler, 'Drupal\\commerce_checkout\\Plugin\\Commerce\\CheckoutPane\\CheckoutPaneInterface', 'Drupal\\commerce_checkout\\Annotation\\CommerceCheckoutPane');
$this
->alterInfo('commerce_checkout_pane_info');
$this
->setCacheBackend($cache_backend, 'commerce_checkout_pane_plugins');
}
public function createInstance($plugin_id, array $configuration = [], CheckoutFlowInterface $checkout_flow = NULL) {
$plugin_definition = $this
->getDefinition($plugin_id);
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
$plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $checkout_flow);
}
else {
$plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $checkout_flow);
}
return $plugin;
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
foreach ([
'id',
'label',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new PluginException(sprintf('The checkout pane %s must define the %s property.', $plugin_id, $required_property));
}
}
}
}