monsieurbiz / SyliusRichEditorPlugin

This plugin add a rich editor on fields to be able to drag and drop elements and edit it.
MIT License
65 stars 36 forks source link

feat: adds the ability to set options to the form #175

Closed delyriand closed 1 year ago

delyriand commented 2 years ago

Example

Define your options in the yaml file :

monsieurbiz_sylius_richeditor:
    ui_elements:
        app.image:
            classes:
                form: App\Form\Type\UiElement\ImageType
            form_options:
                image_width: '700px'
                image_height: '700px'

Create your ui element form with the custom (or not) options:


class ImageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $imageHelpMessage = 'app.ui.help_image_width_max';
        $imageHelpTranslationParameters = [
            '%width%' => $options['image_width'],
        ];
        if (isset($options['image-height'])) {
            $imageHelpMessage = 'app.ui.help_image';
            $imageHelpTranslationParameters['%height%'] = $options['image-height'];
        }

        // ...
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        parent::configureOptions($resolver);
        $resolver->setRequired(['image_width']);
        $resolver->setDefined(['image_height']);
        $resolver->setAllowedTypes('image_width', 'string');
        $resolver->setAllowedTypes('image_height', 'string');
    }
}