Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

How to make certain form fields required? #276

Closed
codeinabox opened this issue Mar 15, 2016 · 5 comments
Closed

How to make certain form fields required? #276

codeinabox opened this issue Mar 15, 2016 · 5 comments

Comments

@codeinabox
Copy link

Is possible to configure, extend or override the SeoMetadataType form to make the title filed required? Using #124 as reference I tried the following code locally but it had no effect

        $builder
            ->add('title', $textType, array('label' => 'form.label_title', 'required' => true))
@dbu
Copy link
Member

dbu commented Mar 29, 2016

i think the easiest would be to extend SeoContentAdminExtension and overwrite configureFormFields to register your own type that makes the fields required. making the form fields required is a general symfony form issue. looking at the code, i fear that for symfony 2.8, overwriting the cmf_seo.form.type.seo_metadata.class parameter no longer works as the form types are identified by class rather than alias.

@dbu
Copy link
Member

dbu commented Mar 31, 2016

for symfony 2.8 and 3, you will need to define your own form type (which can be a class extending the built-in form type and overwrites those fields you want to make required).

a note on usability though: making required seo fields you risk your authors will just copy the title into the fields - its better to have the title of the content required and fall back to that title if the seo data has no specific title. you can set up the seo bundle in a way that it falls back to other fields by adding more extractors and be careful with priority.

@dbu dbu closed this as completed Mar 31, 2016
@codeinabox
Copy link
Author

Thank you, I figured how to make my own custom form. Would you like a
documentation PR in case other people have the same question.

On Thu, 31 Mar 2016, 9:43 a.m. David Buchmann, [email protected]
wrote:

Closed #276 #276.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#276 (comment)

@dbu
Copy link
Member

dbu commented Mar 31, 2016

i would not put an example of how to extend a form - that is already documented in the symfony doc. what would be nice is a .. tip:: block where we document the form type that if you want to customize the form, you just extend the form as explained in the symfony doc, with a link there.

@dbu
Copy link
Member

dbu commented Mar 31, 2016

if you want to add that, please do a PR against the symfony-cmf-docs repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants