BlockManager.php in Multiversion 8
File
src/Block/BlockManager.php
View source
<?php
namespace Drupal\multiversion\Block;
use Drupal\Core\Block\BlockManager as CoreBlockManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\multiversion\Workspace\WorkspaceManagerInterface;
use Psr\Log\LoggerInterface;
class BlockManager extends CoreBlockManager {
protected $database;
protected $workspaceManager;
protected $workspaceCacheKeyPrefix = 'block_plugins:workspace';
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LoggerInterface $logger, Connection $database, WorkspaceManagerInterface $workspace_manager) {
parent::__construct($namespaces, $cache_backend, $module_handler, $logger);
if (floatval(\Drupal::VERSION) < 8.6) {
parent::__construct($namespaces, $cache_backend, $module_handler);
}
else {
parent::__construct($namespaces, $cache_backend, $module_handler, $logger);
}
$this->database = $database;
$this->workspaceManager = $workspace_manager;
}
protected function setCachedDefinitions($definitions) {
$this->cacheKey = $this->workspaceCacheKeyPrefix . $this->workspaceManager
->getActiveWorkspaceId();
parent::setCachedDefinitions($definitions);
}
public function clearCachedDefinitions() {
$active_workspace_id = $this->workspaceManager
->getActiveWorkspaceId();
if (isset($active_workspace)) {
$this->cacheKey = $this->workspaceCacheKeyPrefix . $active_workspace_id;
}
parent::clearCachedDefinitions();
}
protected function getCachedDefinitions() {
$this->cacheKey = $this->workspaceCacheKeyPrefix . $this->workspaceManager
->getActiveWorkspaceId();
parent::getCachedDefinitions();
}
}