Multivalued attributes in Dexterity - plone

With Dexterity I can create a model of contact cards having an email attribute.
class IContact(form.Schema):
email = schema.TextLine(
title=_(u"Email"),
description=_(u"Contact email"),
)
How can I modify this schema to have multiple emails for each contact? I know that it is possible to add emails as a nested content type. Thus, my question is if Dexterity supports multivalued attributes inside content types.

Sure it does, wrap the email TextLine in a schema.List:
schema.List(
title=u"Email adresses",
required=False,
value_type=schema.TextLine(
title=_(u"Email"),
))

Related

Can you make a field unique in a content type in Drupal 8?

I have an employee content type and it have an id field.
Can I make the id field unique (so that Drupal would prevent me from inputting the same id more than once by mistake)?
You could try the field validation module. It allows you to set a field as unique on per content type basis.
Alternatively, if you have access to/are a developer, then it's quite simple to alter the form and include your own validation.
You can use the contrib module unique_content_field_validation

Symfony2 validate only on creation

I have some entity and want to validate one field of this entity only on create object.
Example: I have Post entity and title has to have at least 10 characters when I create Post, but when I update it it can have less characters.
How can I do it with Symfony2? It's possible with default validator and default forms?
You can add the Length constraint for the title attribute to a dedicated validation group that will only be validated when the entity is not updated.

Filter collection based on custom dexterity field

I would like to make a collection which returns my custom dexterity type if it's "featured" field is true. I have added this field to the catalog... is there anything else I need to do to be able to see it in the collection search terms?
When you say "I have added this field to the index" you mean to the portal_catalog?
If yes, you must also configure that index as a new collection criteria. If you are using new style collections you need a Generis Setup import step registry.xml. See plone.app.querystring package: https://github.com/plone/plone.app.querystring/blob/master/plone/app/querystring/profiles/default/registry.xml

How to set relationship when I create a new (custom) content to another (custom) content in Drupal

Premise: I'm new in the world of Drupal, so sorry if this is a stupid question.
What I need is to set some relationships for some new content types I created. For example, I created the "Person" content type and the "Group" content type. Using the "Relation" module I have defined the relation "is in", but now if I want to add a field for setting the relation at creation time, there are no edit widget available. The only way I found to set relationships is using the entity collector: too complicated for a user.
Example: a user creates the Person "John", and he want for him to set the relation "is in" with the Group "Drupal fans". So, during the creation of this Person he needs, for example, a select control that lets him to choose from all the groups already registered in the site.
In brief, I need to manage some entities created by me, with CRUD controls, list, etc. and I need to set some relationships from these entities.
What is the best method/ what are the best module/ how I can do this?
Try the references module: http://drupal.org/project/references
You can create an taxanomy list of your'e groups at Structure -> Taxonomy.
This list you can use in creating an field. By the creation of the field choose for "Term reference" type and then "Autocomplete term widget". Click on save and choose the Taxonomy list that you created.
Hope this is what you need!

Texbox custom representation for Symfony2 entity form type?

My entity Person has a one to many relation with Tag entity. When creating a new person i'd like to show a textbox for assigning tag names separated by commas. User can then input an existent tag name or a new tag name (in this case, a new Tag entity is created and persisted).
Unfortunately entity field type has only checkbox and select representation. How can implement my own textbox representation?
You need to create a custom form type along with a custom data transformer.
This article is a pretty good guide on creating your own form type.
Also, check out Symfony's own source for the EntityType to get an idea of what's going on.
One way would be creating a custom data transformer.

Resources