sulu / SuluFormBundle

Form Bundle for handling Dynamic and Symfony Forms in https://sulu.io
MIT License
81 stars 78 forks source link

Cannot copy a form when the admin locale is not defined in the webspace #364

Open eekes opened 1 year ago

eekes commented 1 year ago
Q A
Bug? yes
New Feature? no
Bundle Version 2.5.2
Sulu Version 2.5.9

Actual Behavior

When trying to copy a form for a locale that's only available in the "admin" part, this line throws this error:

Call to a member function getTitle() on null

Expected Behavior

The form should be copied

Steps to Reproduce

Set this in sulu_admin.yaml:

sulu_core:
    locales:
        nl: Nederlands
        en: English
    translations:
        - nl
        - en

And this in the webspace config:

    <localizations>
        <localization language="en" default="true" />
    </localizations>

Then create a form in the only possible locale (EN) and try to copy a form with the backend locale set to "NL"

Possible Solutions

I could possibly create a merge request, but I'm not sure what you guys would prefer. Use the title of a known locale in the event, or just return an empty string if the form is not available in the admin locale.

alexander-schranz commented 1 year ago

I would go with using a title of a known locale. maybe following is enough:

        $newFormTranslation = $newForm->getTranslation($locale) ?: $newFormTranslation;