Version 1
[yaffs-website] / web / modules / contrib / devel / src / Form / RouterRebuildConfirmForm.php
1 <?php
2
3 namespace Drupal\devel\Form;
4
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Routing\RouteBuilderInterface;
8 use Drupal\Core\Url;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides confirmation form for rebuilding the routes.
13  */
14 class RouterRebuildConfirmForm extends ConfirmFormBase {
15
16   /**
17    * The route builder service.
18    *
19    * @var \Drupal\Core\Routing\RouteBuilderInterface
20    */
21   protected $routeBuilder;
22
23   /**
24    * Constructs a new RouterRebuildConfirmForm object.
25    *
26    * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
27    *   The route builder service.
28    */
29   public function __construct(RouteBuilderInterface $route_builder) {
30     $this->routeBuilder = $route_builder;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public static function create(ContainerInterface $container) {
37     return new static(
38       $container->get('router.builder')
39     );
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getFormId() {
46     return 'devel_menu_rebuild';
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getQuestion() {
53     return $this->t('Are you sure you want to rebuild the router?');
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function getCancelUrl() {
60     return new Url('<front>');
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function getDescription() {
67     return $this->t('Rebuilds the routes information gathering all routing data from .routing.yml files and from classes which subscribe to the route build events. This action cannot be undone.');
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function getConfirmText() {
74     return $this->t('Rebuild');
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function submitForm(array &$form, FormStateInterface $form_state) {
81     $this->routeBuilder->rebuild();
82     drupal_set_message($this->t('The router has been rebuilt.'));
83     $form_state->setRedirect('<front>');
84   }
85
86 }