5 * Contains \Drupal\Console\Command\Image\StylesFlushCommand.
7 namespace Drupal\Console\Command\Image;
9 use Symfony\Component\Console\Input\InputArgument;
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;
17 class StylesFlushCommand extends Command
22 * @var EntityTypeManagerInterface
24 protected $entityTypeManager;
27 * StylesDebugCommand constructor.
29 * @param EntityTypeManagerInterface $entityTypeManager
31 public function __construct(EntityTypeManagerInterface $entityTypeManager)
33 $this->entityTypeManager = $entityTypeManager;
34 parent::__construct();
37 protected function configure()
40 ->setName('image:styles:flush')
41 ->setDescription($this->trans('commands.image.styles.flush.description'))
44 InputArgument::IS_ARRAY | InputArgument::REQUIRED,
45 $this->trans('commands.image.styles.flush.options.image-style')
52 protected function interact(InputInterface $input, OutputInterface $output)
54 $io = new DrupalStyle($input, $output);
55 $styles = $input->getArgument('styles');
57 $imageStyle = $this->entityTypeManager->getStorage('image_style');
58 $styleList = $imageStyle->loadMultiple();
60 foreach ($styleList as $style) {
61 $styleNames[] = $style->get('name');
64 $styles = $io->choice(
65 $this->trans('commands.image.styles.flush.questions.image-style'),
71 $input->setArgument('styles', $styles);
78 protected function execute(InputInterface $input, OutputInterface $output)
80 $io = new DrupalStyle($input, $output);
81 $styles = $input->getArgument('styles');
84 $imageStyle = $this->entityTypeManager->getStorage('image_style');
86 if (in_array('all', $styles)) {
87 $styles = $imageStyle->loadMultiple();
88 foreach ($styles as $style) {
89 $stylesNames[] = $style->get('name');
92 $styles = $stylesNames;
95 foreach ($styles as $style) {
99 $this->trans('commands.image.styles.flush.messages.executing-flush'),
103 $imageStyle->load($style)->flush();
104 } catch (\Exception $e) {
105 watchdog_exception('image', $e);
106 $io->error($e->getMessage());
111 $io->success($this->trans('commands.image.styles.flush.messages.success'));