Custom configuration form error

Hi, I’m trying to make a new plugin for mautic, following the documentation, but, the following error keeps popping up:

An error has occurred resolving the options of the form "MauticPlugin\ExampleBundle\Form\Type\ConfigAuthType": The option "integration" does not exist. Defined options are: "action", "allow_extra_fields", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "help", "help_attr", "help_html", "help_translation_parameters", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "label_translation_parameters", "mapped", "method", "post_max_size_message", "property_path", "required", "row_attr", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

Can someone enlighten me as to why this is happening? Its my first project in mautic, so I can assume its something basic that I’m overlooking.

This is not an error related to Mautic but to Symfony.

You have to pass to the form the option integration, so the form knows that it is allowed:

Thanks, so, the code would look something like this?

class ConfigAuthType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add(
          'key',
          TextType::class,
          [
            'label'    => 'hello_world.form.key',
            'required' => true,
            'attr'     => [
              'class' => 'form-control',
            ],
          ]
        );
        $options = ['integration' => true];
    }
}

I’ve tried it and it still outputs the same error

No, ConfigAuthType::buildForm() actually builds the form.

You have to add the method ConfigAuthType::configureOptions().

Something like this:

class ConfigAuthType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        ...
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            // ...,
            'integration' => true,
        ]);

        $resolver->setAllowedTypes('integration', 'bool');
    }
}

That worked somewhat, but I ended up using another method to do my form, thanks anyways!

What you did?

I ended up using the function “Append to form” in the integration class

public function appendToForm(&$builder, $data, $formArea)
    {
        if ($formArea == 'features') {
            $builder->add(
            'user_name',
                TextType::class,
                [
                    'label'      => 'User ID',
                    'label_attr' => ['class' => 'control-label'],
                    'attr'       => [
                        'class' => 'form-control',
                        'tooltip' => 'Insert a User ID',
                    ],
                    'empty_data' => ''
                ]
            );
    }
1 Like