feat: admin editable email templates
addresses #869eg7ptr
This commit is contained in:
1 parent
804dab335f
commit
3e08965e48
49 files changed
+1760
-276
No files matched your search
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Config\EmailTextDefinition;
|
||||
use App\Entity\EmailText;
|
||||
use App\Validator\KnownPlaceholders;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class EmailTextType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var EmailTextDefinition $definition */
|
||||
$definition = $options['definition'];
|
||||
$placeholders = new KnownPlaceholders($definition->getPlaceholderNames());
|
||||
|
||||
$builder
|
||||
->add('subject', TextType::class, [
|
||||
'label' => 'Betreff',
|
||||
'constraints' => [$placeholders],
|
||||
])
|
||||
->add('headline', TextType::class, [
|
||||
'label' => 'Überschrift',
|
||||
'required' => false,
|
||||
'constraints' => [$placeholders],
|
||||
])
|
||||
->add('body', TextareaType::class, [
|
||||
'label' => 'Text',
|
||||
'attr' => [
|
||||
'data-controller' => 'textarea-autosize',
|
||||
'data-action' => 'textarea-autosize#resize',
|
||||
'data-textarea-autosize-min-rows-value' => 12,
|
||||
],
|
||||
'constraints' => [$placeholders],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
// The list of placeholders is rendered next to the fields, so an admin does not
|
||||
// have to remember which of them this particular mail can fill.
|
||||
$view->vars['definition'] = $options['definition'];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => EmailText::class,
|
||||
])
|
||||
->setRequired('definition')
|
||||
->setAllowedTypes('definition', EmailTextDefinition::class)
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user