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 Drupal\Console\Core\Command\Command;
13 use Drupal\Core\Entity\EntityTypeManagerInterface;
15 class StylesFlushCommand extends Command
18 * @var EntityTypeManagerInterface
20 protected $entityTypeManager;
23 * StylesDebugCommand constructor.
25 * @param EntityTypeManagerInterface $entityTypeManager
27 public function __construct(EntityTypeManagerInterface $entityTypeManager)
29 $this->entityTypeManager = $entityTypeManager;
30 parent::__construct();
33 protected function configure()
36 ->setName('image:styles:flush')
37 ->setDescription($this->trans('commands.image.styles.flush.description'))
40 InputArgument::IS_ARRAY | InputArgument::REQUIRED,
41 $this->trans('commands.image.styles.flush.options.image-style')
42 )->setAliases(['isf']);
48 protected function interact(InputInterface $input, OutputInterface $output)
50 $styles = $input->getArgument('styles');
52 $imageStyle = $this->entityTypeManager->getStorage('image_style');
53 $styleList = $imageStyle->loadMultiple();
55 foreach ($styleList as $style) {
56 $styleNames[] = $style->get('name');
59 $styles = $this->getIo()->choice(
60 $this->trans('commands.image.styles.flush.questions.image-style'),
66 $input->setArgument('styles', $styles);
73 protected function execute(InputInterface $input, OutputInterface $output)
75 $styles = $input->getArgument('styles');
78 $imageStyle = $this->entityTypeManager->getStorage('image_style');
80 if (in_array('all', $styles)) {
81 $styles = $imageStyle->loadMultiple();
82 foreach ($styles as $style) {
83 $stylesNames[] = $style->get('name');
86 $styles = $stylesNames;
89 foreach ($styles as $style) {
93 $this->trans('commands.image.styles.flush.messages.executing-flush'),
97 $imageStyle->load($style)->flush();
98 } catch (\Exception $e) {
99 watchdog_exception('image', $e);
100 $this->getIo()->error($e->getMessage());
105 $this->getIo()->success($this->trans('commands.image.styles.flush.messages.success'));