diff --git a/Command/CreateFieldsOnGroupCommand.php b/Command/CreateFieldsOnGroupCommand.php index db74bccd4..5b2232deb 100644 --- a/Command/CreateFieldsOnGroupCommand.php +++ b/Command/CreateFieldsOnGroupCommand.php @@ -22,11 +22,12 @@ namespace Chill\CustomFieldsBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; +use Symfony\Component\Console\Question\Question; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Exception\ParseException; use Chill\CustomFieldsBundle\Entity\CustomField; @@ -68,9 +69,15 @@ class CreateFieldsOnGroupCommand extends ContainerAwareCommand } } + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { - $dialog = $this->getHelperSet()->get('dialog'); + $helper = $this->getHelperSet()->get('question'); + $em = $this->getContainer() ->get('doctrine.orm.default_entity_manager'); @@ -83,27 +90,32 @@ class CreateFieldsOnGroupCommand extends ContainerAwareCommand . ' Please create at least one.'); } - $table = $this->getHelperSet()->get('table'); - $table->setHeaders(array_merge(array('id', 'entity'), $this->getContainer() - ->getParameter('chill_main.available_languages'))) - ->setRows($this->_prepareRows($customFieldsGroups)); - $table->render($output); + $table = new Table($output); + $table + ->setHeaders(array_merge( + ['id', 'entity'], + $this->getContainer()->getParameter('chill_main.available_languages') + )) + ->setRows($this->_prepareRows($customFieldsGroups)) + ->render() + ; - $customFieldsGroup = $dialog->askAndValidate($output, - "Enter the customfieldGroup's id on which the custom fields " - . "should be added :", + $question = new Question( + "Enter the customfieldGroup's id on which the custom fields should be added: "); + $question->setNormalizer( function($answer) use ($customFieldsGroups) { foreach ($customFieldsGroups as $customFieldsGroup) { if ($answer == $customFieldsGroup->getId()) { return $customFieldsGroup; } } - throw new \RunTimeException('The id does not match an existing ' . 'CustomFieldsGroup'); } ); - + $customFieldsGroup = $helper->ask($input, $output, $question); + + if ($input->getOption(self::ARG_DELETE)) { $this->deleteFieldsForCFGroup($customFieldsGroup); }