Implement custom parsers/renderers with autowiring for snip content
This commit is contained in:
@ -3,17 +3,28 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use App\Service\SnipParser\ParserFactory;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class SnipType extends AbstractType
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ParserFactory $parserFactory,
|
||||
) {}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
dump(iterator_to_array($this->parserFactory->getChoices()));
|
||||
$builder
|
||||
->add('name')
|
||||
->add('parser', ChoiceType::class, [
|
||||
'choice_label' => fn(string $parser) => ucfirst($parser),
|
||||
'choices' => $this->parserFactory->getChoices(),
|
||||
])
|
||||
->add('content', TextareaType::class, [
|
||||
'attr' => ['rows' => 20],
|
||||
'mapped' => false,
|
||||
|
Reference in New Issue
Block a user