public function BootstrapLanguagesBlock::build in Bootstrap Languages 8
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides LanguageBlock::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ BootstrapLanguagesBlock.php, line 60
Class
- BootstrapLanguagesBlock
- Provides a 'Bootstrap Languages' block.
Namespace
Drupal\bootstrap_languages\Plugin\BlockCode
public function build() {
$build = [];
$settings = $this->configuration['bootstrap_language'];
$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__bootstrap_language_block',
'#links' => $links->links,
'#attributes' => [
'class' => [
"language-switcher-{$links->method_id}",
!empty($settings['dropdown_style']) ? "{$settings['dropdown_style']}-dropdown-style" : 'all-dropdown-style',
],
],
'#set_active_class' => TRUE,
'#attached' => [
'library' => [
'bootstrap_languages/default',
],
],
];
}
return $build;
}