426cd82d42b26624165039900ef4391ee24f179b
[ryf-theme.git] / modules / footer / src / Plugin / Block / FooterBlock.php
1 <?php
2 /**
3 * @file
4 * Contains \Drupal\footer\Plugin\Block\FooterBlock.
5 */
6 namespace Drupal\footer\Plugin\Block;
7 use Drupal\Core\Menu\MenuTreeParameters;
8 use Drupal\Core\Block\BlockBase;
9 use Drupal\node\Entity\Node;
10 use Drupal\Core\Block\BlockPluginInterface;
11 use Drupal\Core\Form\FormStateInterface;
12
13
14 /**
15 * Provides a 'footer' block.
16 *
17 * @Block(
18 * id = "footer_block",
19 * admin_label = @Translation("Footer"),
20 * category = @Translation("RYF Custom Module")
21 * )
22 */
23 class FooterBlock extends BlockBase implements BlockPluginInterface {
24 /**
25 * {@inheritdoc}
26 */
27 public function build() {
28
29 $menu_tree_parameters = new MenuTreeParameters();
30 $tree = \Drupal::menuTree()->load('footer', $menu_tree_parameters);
31
32 $cc = 0;
33 foreach($tree as $menu){
34 $title = $menu->link->getTitle();
35 $urlObject = $menu->link->getUrlObject();
36 $url = $urlObject->toString();
37 $weight = $menu->link->getWeight();
38 $enabled = $menu->link->isEnabled();
39
40 if($enabled) {
41 $menu_array[$cc]['title'] = $title;
42 $menu_array[$cc]['url'] = $url;
43 $menu_array[$cc]['weight'] = $weight;
44 $cc++;
45 }
46
47 }
48
49 usort($menu_array, function($a, $b) {
50 return $a['weight'] - $b['weight'];
51 });
52
53 return array(
54 '#theme' => 'footer',
55 '#menu_array' => $menu_array,
56 '#attached' => array(
57 'library' => array(
58 'footer/footer',
59 ),
60 ),
61 );
62
63 }
64 }