fix sf3 deprecated helpers for console command

This commit is contained in:
Tchama 2020-03-13 17:23:22 +01:00
parent 4182c53304
commit 56be317d1b

View File

@ -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.</error>');
}
$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);
}