0

I have a paragraph contact nested inside another paragraph occurrence.

In the widget settings the paragraph contact is defined to be collapsed by default (edit_mode = closed).

I want the contact paragraph only to be open when creating the content and only on the first occurrence.

How can this be achieved?

Thanks in advance.

3
  • 1
    Could you please modify the question to explain the precise meaning of "open" and "closed" in this context?
    – mona lisa
    Apr 14, 2022 at 18:44
  • Do you just need to define a default paragraph bundle on the form display settings for the field?
    – sonfd
    Apr 16, 2022 at 18:07
  • @cilefen with close I mean collapsed an open, the contrary uncollapsed. I edited my question
    – abelass
    Apr 20, 2022 at 7:02

1 Answer 1

0

I achieved what I wanted to to by letting the contact field open by default (edit_mode = open) and then in an hook_form_node_form_alter remove the contact form with this code

// Collapse contact field except for the first occurence.
foreach ($form['field_occurence']['widget'] as $delta => $field) {
  if (is_int($delta) && $delta != 0 && isset($field['subform']['field_contact']['widget']['0']['subform']['#type'])) {
    unset($form['field_occurence']['widget'][$delta]['subform']['field_contact']['widget']['0']);
  }
}

I guess there is a cleaner way but form the moment that does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.