Implement custom parsers/renderers with autowiring for snip content

This commit is contained in:
Tim
2025-04-23 01:06:21 +02:00
parent 5cec259469
commit 943177bc08
15 changed files with 194 additions and 26 deletions

View File

@ -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,