PanelsStorageManager.php in Panels 8.3
File
src/Storage/PanelsStorageManager.php
View source
<?php
namespace Drupal\panels\Storage;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\panels\Annotation\PanelsStorage;
use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
class PanelsStorageManager extends DefaultPluginManager implements PanelsStorageManagerInterface {
protected $currentUser;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, AccountProxyInterface $current_user) {
parent::__construct('Plugin/PanelsStorage', $namespaces, $module_handler, PanelsStorageInterface::class, PanelsStorage::class);
$this->currentUser = $current_user;
$this
->alterInfo('panels_storage_info');
$this
->setCacheBackend($cache_backend, 'panels_storage');
}
protected $storage = [];
protected function getStorage($storage_type) {
if (!isset($this->storage[$storage_type])) {
$this->storage[$storage_type] = $this
->createInstance($storage_type);
}
return $this->storage[$storage_type];
}
public function load($storage_type, $id) {
$storage = $this
->getStorage($storage_type);
return $storage
->load($id);
}
public function save(PanelsDisplayVariant $panels_display) {
$storage = $this
->getStorage($panels_display
->getStorageType());
$storage
->save($panels_display);
}
public function access($storage_type, $id, $op, AccountInterface $account = NULL) {
if ($account === NULL) {
$account = $this->currentUser
->getAccount();
}
return $this
->getStorage($storage_type)
->access($id, $op, $account);
}
}