class WorkspaceSwitcherBlock

Same name and namespace in other branches
  1. 11.x core/modules/workspaces/src/Plugin/Block/WorkspaceSwitcherBlock.php \Drupal\workspaces\Plugin\Block\WorkspaceSwitcherBlock
  2. 10 core/modules/workspaces/src/Plugin/Block/WorkspaceSwitcherBlock.php \Drupal\workspaces\Plugin\Block\WorkspaceSwitcherBlock
  3. 9 core/modules/workspaces/src/Plugin/Block/WorkspaceSwitcherBlock.php \Drupal\workspaces\Plugin\Block\WorkspaceSwitcherBlock

Provides a 'Workspace switcher' block.

Plugin annotation


@Block(
  id = "workspace_switcher",
  admin_label = @Translation("Workspace switcher"),
  category = @Translation("Workspace"),
)

Hierarchy

Expanded class hierarchy of WorkspaceSwitcherBlock

File

core/modules/workspaces/src/Plugin/Block/WorkspaceSwitcherBlock.php, line 21

Namespace

Drupal\workspaces\Plugin\Block
View source
class WorkspaceSwitcherBlock extends BlockBase implements ContainerFactoryPluginInterface {
  
  /**
   * The form builder.
   *
   * @var \Drupal\Core\Form\FormBuilderInterface
   */
  protected $formBuilder;
  
  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;
  
  /**
   * Constructs a new WorkspaceSwitcherBlock instance.
   *
   * @param array $configuration
   *   The plugin configuration.
   * @param string $plugin_id
   *   The plugin ID.
   * @param mixed $plugin_definition
   *   The plugin definition.
   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
   *   The form builder.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  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;
  }
  
  /**
   * {@inheritdoc}
   */
  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'));
  }
  
  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
BlockPluginInterface::BLOCK_LABEL_VISIBLE constant Indicates the block label (title) should be displayed to end users.
BlockPluginTrait::$transliteration protected property The transliteration service.
BlockPluginTrait::access public function
BlockPluginTrait::baseConfigurationDefaults protected function Returns generic default configuration for block plugins.
BlockPluginTrait::blockAccess protected function Indicates whether the block should be shown.
BlockPluginTrait::blockForm public function 1
BlockPluginTrait::blockSubmit public function
BlockPluginTrait::blockValidate public function
BlockPluginTrait::buildConfigurationForm public function Creates a generic configuration form for all block types. Individual
block plugins can add elements to this form by overriding
BlockBase::blockForm(). Most block plugins should not override this
method unless they need to alter the generic form elements.
BlockPluginTrait::calculateDependencies public function
BlockPluginTrait::defaultConfiguration public function
BlockPluginTrait::getConfiguration public function
BlockPluginTrait::getMachineNameSuggestion public function
BlockPluginTrait::getPreviewFallbackString public function
BlockPluginTrait::label public function
BlockPluginTrait::setConfiguration public function
BlockPluginTrait::setConfigurationValue public function
BlockPluginTrait::setTransliteration public function Sets the transliteration service.
BlockPluginTrait::submitConfigurationForm public function Most block plugins should not override this method. To add submission
handling for a specific block type, override BlockBase::blockSubmit().
BlockPluginTrait::transliteration protected function Wraps the transliteration service.
BlockPluginTrait::validateConfigurationForm public function Most block plugins should not override this method. To add validation
for a specific block type, override BlockBase::blockValidate().
ContextAwarePluginAssignmentTrait::addContextAssignmentElement protected function Builds a form element for assigning a context to a given slot.
ContextAwarePluginAssignmentTrait::contextHandler protected function Wraps the context handler.
ContextAwarePluginBase::$context protected property The data objects representing the context of this plugin.
ContextAwarePluginBase::$contexts Deprecated private property Data objects representing the contexts passed in the plugin configuration.
ContextAwarePluginBase::createContextFromConfiguration protected function
ContextAwarePluginBase::getCacheContexts public function
ContextAwarePluginBase::getCacheMaxAge public function 1
ContextAwarePluginBase::getCacheTags public function
ContextAwarePluginBase::getContext public function This code is identical to the Component in order to pick up a different
Context class.
ContextAwarePluginBase::getContextDefinition public function
ContextAwarePluginBase::getContextDefinitions public function
ContextAwarePluginBase::getContextMapping public function
ContextAwarePluginBase::getContexts public function
ContextAwarePluginBase::getContextValue public function
ContextAwarePluginBase::getContextValues public function
ContextAwarePluginBase::setContext public function
ContextAwarePluginBase::setContextMapping public function
ContextAwarePluginBase::setContextValue public function
ContextAwarePluginBase::validateContexts public function
ContextAwarePluginBase::__get public function Implements magic __get() method.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function
DependencySerializationTrait::__wakeup public function
MessengerTrait::$messenger protected property The messenger. 3
MessengerTrait::messenger public function Gets the messenger. 3
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function
PluginBase::getDerivativeId public function
PluginBase::getPluginDefinition public function 1
PluginBase::getPluginId public function
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginWithFormsTrait::getFormClass public function
PluginWithFormsTrait::hasFormClass public function
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 1
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager.
TypedDataTrait::setTypedDataManager public function Sets the typed data manager.
WorkspaceSwitcherBlock::$entityTypeManager protected property The entity type manager.
WorkspaceSwitcherBlock::$formBuilder protected property The form builder.
WorkspaceSwitcherBlock::build public function Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface::build
WorkspaceSwitcherBlock::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
WorkspaceSwitcherBlock::__construct public function Constructs a new WorkspaceSwitcherBlock instance. Overrides BlockPluginTrait::__construct

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.