Want to extend fields

Topics: Customizing Orchard, Localization, Writing modules
Aug 3, 2011 at 7:56 AM

I'm now working in building some new fields modules like numbers and booleans, also want to extend the functionality of fields in another contrib-module, so in the add/edit page of field where the admin set the filed's machine name, I want to:

  1. Add localizable human name property for the field, the machine name is so ugly to be displayed to the data entry guys specially in localizable applications.
  2. Add 'Required?' checkbox, so can enforce users to add values for that field if required.
  3. Add a default value input for the field.
  4. Some other inputs for each field type, like range inputs in case of number field.

The question is: Where to start? what to extend/implement? and how to add validation for fields?

Developer
Aug 3, 2011 at 9:53 AM

1. Localize the name can be done with Localizer T : In your view, you should use the name of the field surrounded by T("") so that the designer/developper can add .po file to manage the translation in the Theme.

2. Some Fields have DefinitionTemplate that can be used to add Settings between the Field and the ContentType (e.g : Contrib.Taxonomies). You could manage the validation with this.

3. Same way : You can specify a default value in a DefinitionTemplate and add the property in view model to initialize the field.

4. I think it would be very interesting to make Fields that allow to create HTML 5 Markup and Attributes (and use Modernizer to fallback when attributes are not managed by the browser).

Aug 6, 2011 at 8:50 AM
agriffard wrote:

1. Localize the name can be done with Localizer T : In your view, you should use the name of the field surrounded by T("") so that the designer/developper can add .po file to manage the translation in the Theme.

2. Some Fields have DefinitionTemplate that can be used to add Settings between the Field and the ContentType (e.g : Contrib.Taxonomies). You could manage the validation with this.

3. Same way : You can specify a default value in a DefinitionTemplate and add the property in view model to initialize the field.

4. I think it would be very interesting to make Fields that allow to create HTML 5 Markup and Attributes (and use Modernizer to fallback when attributes are not managed by the browser).

Thanks for the answer, but I think for the localization problem, T("") will not solve the problem. As for a field named PublishDate, I want it to be displayed 'Publish date' for the default culture. Also T("") is not for entry data but for hard-coded strings.