WorkspaceSwitcherBlock.php in Drupal 9
File
core/modules/workspaces/src/Plugin/Block/WorkspaceSwitcherBlock.php
View source
<?php
namespace Drupal\workspaces\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\workspaces\Form\WorkspaceSwitcherForm;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WorkspaceSwitcherBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $formBuilder;
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $form_builder, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formBuilder = $form_builder;
$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('form_builder'), $container
->get('entity_type.manager'));
}
public function build() {
$build = [
'form' => $this->formBuilder
->getForm(WorkspaceSwitcherForm::class),
'#cache' => [
'contexts' => $this->entityTypeManager
->getDefinition('workspace')
->getListCacheContexts(),
'tags' => $this->entityTypeManager
->getDefinition('workspace')
->getListCacheTags(),
],
];
return $build;
}
}