Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
StatisticsMigrateController | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
create | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
migrate | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Drupal\visitors\Controller; |
4 | |
5 | use Drupal\Core\Controller\ControllerBase; |
6 | use Drupal\Core\Extension\ModuleHandlerInterface; |
7 | use Drupal\Core\Form\FormBuilderInterface; |
8 | use Drupal\Core\Messenger\MessengerInterface; |
9 | use Drupal\Core\Url; |
10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
11 | use Symfony\Component\HttpFoundation\RedirectResponse; |
12 | |
13 | /** |
14 | * Controller for the statistics migration form. |
15 | */ |
16 | class StatisticsMigrateController extends ControllerBase { |
17 | |
18 | /** |
19 | * The module handler. |
20 | * |
21 | * @var \Drupal\Core\Extension\ModuleHandlerInterface |
22 | */ |
23 | protected $moduleHandler; |
24 | |
25 | /** |
26 | * The form builder. |
27 | * |
28 | * @var \Drupal\Core\Form\FormBuilderInterface |
29 | */ |
30 | protected $formBuilder; |
31 | |
32 | /** |
33 | * Constructs the counter service. |
34 | * |
35 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
36 | * The module handler. |
37 | * @param \Drupal\Core\Form\FormBuilderInterface $form_builder |
38 | * The form builder. |
39 | * @param \Drupal\Core\Messenger\MessengerInterface $messenger |
40 | * The messenger. |
41 | */ |
42 | public function __construct(ModuleHandlerInterface $module_handler, FormBuilderInterface $form_builder, MessengerInterface $messenger) { |
43 | $this->moduleHandler = $module_handler; |
44 | $this->formBuilder = $form_builder; |
45 | $this->setMessenger($messenger); |
46 | } |
47 | |
48 | /** |
49 | * {@inheritdoc} |
50 | */ |
51 | public static function create(ContainerInterface $container) { |
52 | return new static( |
53 | $container->get('module_handler'), |
54 | $container->get('form_builder'), |
55 | $container->get('messenger'), |
56 | ); |
57 | } |
58 | |
59 | /** |
60 | * Migrate statistics. |
61 | */ |
62 | public function migrate() { |
63 | |
64 | $statistics_is_installed = $this->moduleHandler->moduleExists('statistics'); |
65 | if (!$statistics_is_installed) { |
66 | $this->messenger()->addWarning('The Statistics module is not installed.'); |
67 | $url = Url::fromRoute('visitors.settings'); |
68 | $response = new RedirectResponse($url->toString()); |
69 | return $response->send(); |
70 | } |
71 | |
72 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\StatisticsMigrateForm'); |
73 | return $form; |
74 | } |
75 | |
76 | } |