ecb510e489245ede9e7d187c21aa7a2413bfbb25
[yaffs-website] / vendor / drupal / console / src / Command / Shared / MenuTrait.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Command\Shared\MenuTrait.
6  */
7
8 namespace Drupal\Console\Command\Shared;
9
10 use Drupal\Console\Core\Style\DrupalStyle;
11 use Symfony\Component\Yaml\Parser;
12
13 /**
14  * Class MenuTrait
15  *
16  * @package Drupal\Console\Command
17  */
18 trait MenuTrait
19 {
20     /**
21      * @param \Drupal\Console\Core\Style\DrupalStyle $io
22      * @param string                                 $className The form class name
23      * @return string
24      * @throws \Exception
25      */
26     public function menuQuestion(DrupalStyle $io, $className)
27     {
28         if ($io->confirm(
29             $this->trans('commands.generate.form.questions.menu_link_gen'),
30             true
31         )
32         ) {
33             // now we need to ask them where to gen the form
34             // get the route
35             $menu_options = [
36                 'menu_link_gen' => true,
37             ];
38             $menu_link_title = $io->ask(
39                 $menu_link_title = $this->trans('commands.generate.form.questions.menu_link_title'),
40                 $className
41             );
42             $menuLinkFile = sprintf(
43                 '%s/core/modules/system/system.links.menu.yml',
44                 $this->appRoot
45             );
46
47             $parser = new Parser();
48             $menuLinkContent = $parser->parse(file_get_contents($menuLinkFile));
49
50
51             $menu_parent = $io->choiceNoList(
52                 $menu_parent = $this->trans('commands.generate.form.questions.menu_parent'),
53                 array_keys($menuLinkContent),
54                 'system.admin_config_system'
55             );
56
57             $menu_link_desc = $io->ask(
58                 $menu_link_desc = $this->trans('commands.generate.form.questions.menu_link_desc'),
59                 'A description for the menu entry'
60             );
61             $menu_options['menu_link_title'] = $menu_link_title;
62             $menu_options['menu_parent'] = $menu_parent;
63             $menu_options['menu_link_desc'] = $menu_link_desc;
64             return $menu_options;
65         }
66     }
67 }