选择输入TYPO3 v9 Symfony命令

问题描述

我想在TYPO3 v9中发出调度程序命令,问题是我不知道并且找不到如何进行选择输入。

这就是我所拥有的:

/**
 * Basic configuration(s) for the command.
 */
protected function configure(): void
{
    $this->setName('WiRo Workflow')
        ->setDescription('Sendet eine E-Mail an den Redakteur,wenn Inhaltselemente länger als 6 Monate nicht bearbeitet wurden')
        ->addArgument('mailFrom',InputArgument::required,'Absender-Adresse')
        ->addArgument('mailFromName','Absender-Name')
        ->addArgument('mailTo',InputArgument::OPTIONAL,'Empfänger-Adresse (nur für Chefredakteure und Administratoren)')
        ->addOption(
            'colors',['blue','red'],Inputoption::VALUE_required | Inputoption::VALUE_IS_ARRAY,'Which colors do you like?','red']
        )
        ->addOption('optionTV',null,Inputoption::VALUE_OPTIONAL,'Benachrichtigung an: Themenverantwortlicher')
        ->addOption('optionAdmin',Inputoption::VALUE_NONE,'admin')
        ->addOption('optionAdminAct','Benachrichtigung an: Chefredakteur und Administratoren (Aktualisierung)')
        ->addArgument('mailTimetocheck','Anzahl Monate der Seiten,die zu prüfen sind:')
        ->addArgument('urlMandant','URL des Mandanten')
        ->addArgument('pageContact','Themenverantwortliche beziehen aus:')
        ->addArgument('rootPageID','Root-Page')
        ->addArgument('excludePages','Auszuschließende Seiten (Komma separierte Liste)')
        ->addArgument('mailSignature','Mail-Signatur');
}

解决方法

您不能在命令选项上放置用户选择问题...,相反,您必须对ChoiceQuestion对象使用帮助程序的Asking方法

  • 按照您的命令

use Symfony\Component\Console\Question\ChoiceQuestion;

// ...
/**
 * Basic configuration(s) for the command.
 */
protected function configure(): void
{
    $this->setName('WiRo Workflow')
        ->setDescription('Sendet eine E-Mail an den Redakteur,wenn Inhaltselemente länger als 6 Monate nicht bearbeitet wurden')
        ->addArgument('mailFrom',InputArgument::REQUIRED,'Absender-Adresse')
        ->addArgument('mailFromName','Absender-Name')
        ->addArgument('mailTo',InputArgument::OPTIONAL,'Empfänger-Adresse (nur für Chefredakteure und Administratoren)')
        ->addOption('optionTV',null,InputOption::VALUE_OPTIONAL,'Benachrichtigung an: Themenverantwortlicher')
        ->addOption('optionAdmin',InputOption::VALUE_NONE,'admin')
        ->addOption('optionAdminAct','Benachrichtigung an: Chefredakteur und Administratoren (Aktualisierung)')
        ->addArgument('mailTimeToCheck','Anzahl Monate der Seiten,die zu prüfen sind:')
        ->addArgument('urlMandant','URL des Mandanten')
        ->addArgument('pageContact','Themenverantwortliche beziehen aus:')
        ->addArgument('rootPageID','Root-Page')
        ->addArgument('excludePages','Auszuschließende Seiten (Komma separierte Liste)')
        ->addArgument('mailSignature','Mail-Signatur');
}

protected function execute(InputInterface $input,OutputInterface $output): int
{
    //...

    $helper = $this->getHelper('question');
    $question = new ChoiceQuestion(
        'Which colors do you like?',['blue','red'],0 // default is blue
    );

    $question->setErrorMessage('Color %s is invalid.');

    $color = $helper->ask($input,$output,$question);
    $output->writeln('You have just selected: ' . $color);

    // doSomething with $color


    return 0;
}
//...