Score:0

Custom constraints validation of multi value paragraphs: highlighting missing field

nl flag

I am using constraint for the validation my multi value paragraph field.

I can correctly implement the different validation rules but I haven't found out how to highlight only the erroneous field(s).

Here is my violation declaration

      $this->context
       ->buildViolation($constraint->modaliteRequise)
       ->atPath((string) $delta . 'subform.field_modalite.0')
       ->addViolation();

This highlights all fields of all paragraphs.

How can I only highlight the missing field in the affected paragraph?

Thanks Rainer

Score:0
nl flag

Ok, I finally found it thanks to https://www.drupal.org/project/paragraphs/issues/2994660#comment-12740155

With following path I can correctly target the field

->atPath((string) $delta . '.subform.field_modalite.widget')

If you want to target a paragraph field from inside another paragraph field you need a path as follows

->atPath((string) '0.subform.TARGET_FIELD.widget.0.subform')
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.