class LanguageBlock
Same name in this branch
- 8.9.x core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock
Same name in other branches
- 9 core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock
- 9 core/modules/language/src/Plugin/Block/LanguageBlock.php \Drupal\language\Plugin\Block\LanguageBlock
- 10 core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock
- 10 core/modules/language/src/Plugin/Block/LanguageBlock.php \Drupal\language\Plugin\Block\LanguageBlock
- 11.x core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock
- 11.x core/modules/language/src/Plugin/Block/LanguageBlock.php \Drupal\language\Plugin\Block\LanguageBlock
Provides a 'Language switcher' block.
Plugin annotation
@Block(
id = "language_block",
admin_label = @Translation("Language switcher"),
category = @Translation("System"),
deriver = "Drupal\language\Plugin\Derivative\LanguageBlock"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\ContextAwarePluginBase implements \Drupal\Core\Plugin\ContextAwarePluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Block\BlockBase extends \Drupal\Core\Plugin\ContextAwarePluginBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Render\PreviewFallbackInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\language\Plugin\Block\LanguageBlock extends \Drupal\Core\Block\BlockBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Block\BlockBase extends \Drupal\Core\Plugin\ContextAwarePluginBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Render\PreviewFallbackInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\ContextAwarePluginBase implements \Drupal\Core\Plugin\ContextAwarePluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\ContextAwarePluginInterface
Expanded class hierarchy of LanguageBlock
File
-
core/
modules/ language/ src/ Plugin/ Block/ LanguageBlock.php, line 24
Namespace
Drupal\language\Plugin\BlockView source
class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The path matcher.
*
* @var \Drupal\Core\Path\PathMatcherInterface
*/
protected $pathMatcher;
/**
* Constructs an LanguageBlock object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
* The path matcher.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, PathMatcherInterface $path_matcher) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->languageManager = $language_manager;
$this->pathMatcher = $path_matcher;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('language_manager'), $container->get('path.matcher'));
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
$access = $this->languageManager
->isMultilingual() ? AccessResult::allowed() : AccessResult::forbidden();
return $access->addCacheTags([
'config:configurable_language_list',
]);
}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$route_name = $this->pathMatcher
->isFrontPage() ? '<front>' : '<current>';
$type = $this->getDerivativeId();
$links = $this->languageManager
->getLanguageSwitchLinks($type, Url::fromRoute($route_name));
if (isset($links->links)) {
$build = [
'#theme' => 'links__language_block',
'#links' => $links->links,
'#attributes' => [
'class' => [
"language-switcher-{$links->method_id}",
],
],
'#set_active_class' => TRUE,
];
}
return $build;
}
/**
* {@inheritdoc}
*
* @todo Make cacheable in https://www.drupal.org/node/2232375.
*/
public function getCacheMaxAge() {
return 0;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
LanguageBlock::$languageManager | protected | property | The language manager. | |
LanguageBlock::$pathMatcher | protected | property | The path matcher. | |
LanguageBlock::blockAccess | protected | function | ||
LanguageBlock::build | public | function | ||
LanguageBlock::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create |
LanguageBlock::getCacheMaxAge | public | function | @todo Make cacheable in https://www.drupal.org/node/2232375. | |
LanguageBlock::__construct | public | function | Constructs an LanguageBlock object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.