Newer
Older
Dries Buytaert
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @file
* Contains \Drupal\language\Plugin\block\block\LanguageBlock.
*/
namespace Drupal\language\Plugin\block\block;
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Provides a 'Language switcher' block.
*
* @Plugin(
* id = "language_block",
* subject = @Translation("Language switcher"),
* module = "language",
* derivative = "Drupal\language\Plugin\Derivative\LanguageBlock"
* )
*/
class LanguageBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::blockAccess().
*/
function blockAccess() {
return language_multilingual();
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
public function blockBuild() {
$path = drupal_is_front_page() ? '<front>' : current_path();
list($plugin_id, $type) = explode(':', $this->getPluginId());
$links = language_negotiation_get_switch_links($type, $path);
if (isset($links->links)) {
return array(
'#theme' => 'links__language_block',
'#links' => $links->links,
'#attributes' => array(
'class' => array(
"language-switcher-{$links->method_id}",
),
),
);
}
}
}