X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FTwigExtensionCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FTwigExtensionCommand.php;h=843803d4a52e1942ee9dfd84ad21272644cfa432;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php b/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php new file mode 100644 index 000000000..843803d4a --- /dev/null +++ b/vendor/drupal/console/src/Command/Generate/TwigExtensionCommand.php @@ -0,0 +1,191 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->site = $site; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:twig:extension') + ->setDescription($this->trans('commands.generate.twig.extension.description')) + ->setHelp($this->trans('commands.generate.twig.extension.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.twig.extension.options.name') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.class') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return; + } + + $module = $input->getOption('module'); + $name = $input->getOption('name'); + $class = $input->getOption('class'); + $services = $input->getOption('services'); + // Add renderer service as first parameter. + array_unshift($services, 'renderer'); + + + // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + + $this->generator->generate($module, $name, $class, $build_services); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // --module option + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + // --name option + $name = $input->getOption('name'); + if (!$name) { + $name = $io->ask( + $this->trans('commands.generate.twig.extension.questions.twig-extension'), + $module.'.twig.extension' + ); + $input->setOption('name', $name); + } + + // --class option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.common.options.class'), + 'DefaultTwigExtension' + ); + $input->setOption('class', $class); + } + + // --services option + $services = $input->getOption('services'); + if (!$services) { + // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + } + } +}