Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden field types should not be defined statically #397

Open
Dodger77 opened this issue Sep 6, 2024 · 0 comments
Open

Hidden field types should not be defined statically #397

Dodger77 opened this issue Sep 6, 2024 · 0 comments

Comments

@Dodger77
Copy link

Dodger77 commented Sep 6, 2024

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);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant