db backup prior to drupal security update
[yaffs-website] / vendor / drupal / console / src / Command / Image / StylesDebugCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Image\StylesDebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Image;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Core\Entity\EntityTypeManagerInterface;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Console\Core\Style\DrupalStyle;
16
17 /**
18  * Class StylesDebugCommand
19  *
20  * @package Drupal\Console\Command\Image
21  */
22 class StylesDebugCommand extends Command
23 {
24     use CommandTrait;
25
26     /**
27      * @var EntityTypeManagerInterface
28      */
29     protected $entityTypeManager;
30
31     /**
32      * StylesDebugCommand constructor.
33      *
34      * @param EntityTypeManagerInterface $entityTypeManager
35      */
36     public function __construct(EntityTypeManagerInterface $entityTypeManager)
37     {
38         $this->entityTypeManager = $entityTypeManager;
39         parent::__construct();
40     }
41
42     /**
43      * {@inheritdoc}
44      */
45     protected function configure()
46     {
47         $this
48             ->setName('image:styles:debug')
49             ->setDescription($this->trans('commands.image.styles.debug.description'));
50     }
51
52     /**
53      * {@inheritdoc}
54      */
55     protected function execute(InputInterface $input, OutputInterface $output)
56     {
57         $io = new DrupalStyle($input, $output);
58
59         $imageStyle = $this->entityTypeManager->getStorage('image_style');
60
61         $io->newLine();
62         $io->comment(
63             $this->trans('commands.image.styles.debug.messages.styles-list')
64         );
65
66         if ($imageStyle) {
67             $this->imageStyleList($io, $imageStyle);
68         }
69
70         return 0;
71     }
72
73     /**
74      * @param \Drupal\Console\Core\Style\DrupalStyle $io
75      * @param $imageStyle
76      */
77     protected function imageStyleList(DrupalStyle $io, $imageStyle)
78     {
79         $tableHeader = [
80           $this->trans('commands.image.styles.debug.messages.styles-name'),
81           $this->trans('commands.image.styles.debug.messages.styles-label')
82         ];
83
84         $tableRows = [];
85
86         foreach ($imageStyle->loadMultiple() as $styles) {
87             $tableRows[] = [
88               $styles->get('name'),
89               $styles->get('label')
90             ];
91         }
92
93         $io->table(
94             $tableHeader,
95             $tableRows
96         );
97     }
98 }