CheckoutPaneManager.php in Ubercart 8.4
File
uc_cart/src/Plugin/CheckoutPaneManager.php
View source
<?php
namespace Drupal\uc_cart\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\uc_cart\Annotation\CheckoutPane;
use Drupal\uc_cart\CheckoutPanePluginInterface;
class CheckoutPaneManager extends DefaultPluginManager {
protected $paneConfig;
protected $defaults = [
'status' => TRUE,
'weight' => 0,
];
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Ubercart/CheckoutPane', $namespaces, $module_handler, CheckoutPanePluginInterface::class, CheckoutPane::class);
$this
->alterInfo('uc_checkout_pane');
$this
->setCacheBackend($cache_backend, 'uc_checkout_panes');
$this->paneConfig = \Drupal::config('uc_cart.settings')
->get('panes');
}
public function getPanes(array $filter = []) {
$instances = [];
foreach ($this
->getDefinitions() as $id => $definition) {
foreach ($filter as $key => $value) {
if (isset($definition[$key]) && $definition[$key] == $value) {
continue 2;
}
}
$instance = $this
->createInstance($id, $this->paneConfig[$id] ?: []);
if (!isset($filter['enabled']) || $filter['enabled'] != $instance
->isEnabled()) {
$instances[$id] = $instance;
}
}
uasort($instances, [
$this,
'sortHelper',
]);
return $instances;
}
public function sortHelper($a, $b) {
$a_weight = $a
->getWeight();
$b_weight = $b
->getWeight();
if ($a_weight == $b_weight) {
return 0;
}
return $a_weight < $b_weight ? -1 : 1;
}
}