Limenius / LiformBundle

Symfony Bundle to render Symfony Forms to JSON Schema
MIT License
138 stars 44 forks source link

Impossible to not have a title #29

Closed laurent-bientz closed 1 year ago

laurent-bientz commented 3 years ago

Hi,

In a FormType, if we have 'label' => false, it's normalized by the form name instead of null (or a blank string if we want to follow the RFC).

In your code:

protected function addLabel(FormInterface $form, array $schema)
{
    $translationDomain = $form->getConfig()->getOption('translation_domain');
    if ($label = $form->getConfig()->getOption('label')) {
        $schema['title'] = $this->translator->trans($label, [], $translationDomain);
    } else {
        $schema['title'] = $this->translator->trans($form->getName(), [], $translationDomain);
    }

    return $schema;
}

should be changed by:


protected function addLabel(FormInterface $form, array $schema)
{
    $translationDomain = $form->getConfig()->getOption('translation_domain');
    if ($label = $form->getConfig()->getOption('label')) {
        $schema['title'] = $this->translator->trans($label, [], $translationDomain);
    } elseif (false === $form->getConfig()->getOption('label')) {
        $schema['title'] = '';
    } else {
        $schema['title'] = $this->translator->trans($form->getName(), [], $translationDomain);
    }

    return $schema;
}