a bunch of fixes to utilize the block plugin system instead of the old hooks, mostly...
[sandbox/Crell/1260830.git] / core / includes / Drupal / Plugin / Core / SystemMenuBlock.php
1 <?php
2
3 namespace Drupal\Plugin\Core;
4 use Drupal\Plugin\PluginChildrenInterface;
5
6 /**
7 * @file
8 * System module block for rendering system menus from the
9 * menu_list_system_menus() funtion.
10 */
11 class SystemMenuBlock extends AbstractBlock implements PluginChildrenInterface {
12 protected $children;
13 protected $child;
14
15 /**
16 * Implements AccessInterface::access().
17 */
18 public function access() {
19 global $user;
20 if (!$user->uid) {
21 return FALSE;
22 }
23 return parent::access();
24 }
25
26 /**
27 * Implements PluginChildrenInterface::getChild().
28 */
29 public function getChild($child) {
30 $this->child = $child;
31 if (!isset($this->children[$child])) {
32 $this->getChildren();
33 }
34 if(isset($this->children[$child])) {
35 $this->config = $this->children[$child];
36 return $this->children[$child];
37 }
38 return array();
39 }
40
41 /**
42 * Implements PluginChildrenInterface::getChildren().
43 */
44 public function getChildren() {
45 foreach (menu_list_system_menus() as $menu => $name) {
46 $this->children[$menu] = clone($this->config);
47 $this->children[$menu]->delta = $menu;
48 $this->children[$menu]->subject = $name;
49 }
50 return $this->children;
51 }
52
53 /**
54 * Implements BlockInterface::info().
55 */
56 public function info() {
57 $args = func_get_args();
58 $child = $this->getChild($args[0]);
59 if ($child) {
60 return array(
61 'info' => $child->subject,
62 'cache' => DRUPAL_NO_CACHE,
63 );
64 }
65 return array(
66 'info' => 'Menu Block',
67 'cache' => DRUPAL_NO_CACHE,
68 );
69 }
70
71 /**
72 * Implements BlockInterface::build().
73 */
74 public function build() {
75 return array(
76 '#block' => $this->children[$this->child],
77 menu_tree($this->child),
78 );
79 }
80 }