WorkspaceBlock.php in Workspace 8
File
src/Plugin/Block/WorkspaceBlock.php
View source
<?php
namespace Drupal\workspace\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\multiversion\Workspace\WorkspaceManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WorkspaceBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $workspaceManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, WorkspaceManagerInterface $workspace_manager, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->workspaceManager = $workspace_manager;
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('workspace.manager'), $container
->get('entity_type.manager'));
}
public function build() {
$build = [
'#pre_render' => [
'workspace.toolbar:preRenderWorkspaceSwitcherForms',
],
'workspace_forms' => [],
'#attached' => [
'library' => [
'workspace/drupal.workspace.switcher',
],
],
'#cache' => [
'contexts' => $this->entityTypeManager
->getDefinition('workspace')
->getListCacheContexts(),
'tags' => $this->entityTypeManager
->getDefinition('workspace')
->getListCacheTags(),
],
];
return $build;
}
}
Classes
Name |
Description |
WorkspaceBlock |
Plugin annotation
@Block(
id = "workspace_switcher_block",
admin_label = @Translation("Workspace switcher"),
category = @Translation("Workspace"),
) |