Skip to content

Hidden field types should not be defined statically #397

@Dodger77

Description

@Dodger77
Q A
Bug? no
New Feature? yes
Bundle Version 2.5.4
Sulu Version 2.5.20
Browser Version -

Actual Behavior

Hidden field types are defined statically (see

public static $HIDDEN_TYPES = [
) to ensure that for these fields no columns are shown in the data tab of the form in which the field type is used.

When using own field types columns for these types are shown, even it has the mapped option set to false.

Expected Behavior

Own field types should have the possibility to be defined as a "hidden" field type so that for it no column in the data tab is shown.

Steps to Reproduce

Example for a FriendlyCaptcha field type

Type config:


<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <service id="sulu_form.dynamic.type_friendlycaptcha" class="App\Form\FormBundle\FriendlyCaptchaFieldType">
            <tag name="sulu_form.dynamic.type" alias="friendlycaptcha"/>
        </service>
    </services>
</container>

Field type class:


namespace App\Form\FormBundle;

use CORS\Bundle\FriendlyCaptchaBundle\Form\Type\FriendlyCaptchaType;
use CORS\Bundle\FriendlyCaptchaBundle\Validator\FriendlyCaptchaValid;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeConfiguration;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
use Sulu\Bundle\FormBundle\Dynamic\Types\SimpleTypeTrait;
use Sulu\Bundle\FormBundle\Entity\FormField;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * FriendlyCaptcha form field type for SuluFormBundle
 *
 * @link https://friendlycaptcha.com
 * @see  https://github.com/sulu/SuluFormBundle
 *
 */
class FriendlyCaptchaFieldType implements FormFieldTypeInterface
{
    use SimpleTypeTrait;

    public function getConfiguration(): FormFieldTypeConfiguration
    {
        return new FormFieldTypeConfiguration(
            'FriendlyCaptcha', 
            __DIR__ . '/../../../config/form-bundle/field_friendlycaptcha.xml', 
            'special'
        );
    }

    public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
    {
        // Use in this way the friendlycaptcha bundle could maybe not exists.
        $options['mapped']      = false;
        $options['required']    = true;
        $options['constraints'] = new FriendlyCaptchaValid();
        $builder->add($field->getKey(), FriendlyCaptchaType::class, $options);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions