Score:1

How can I access the parent entity values inside a custom paragraph formElement?

in flag

I created a select custom field that must be inserted inside a paragraph and the options values are dynamically inserted based on another reference field present in the paragraph itself. How can I access the actual paragraph instance to read the value of the reference field, so I can manage the right values inside the formElement function of the custom field?

Score:2
cn flag

You can get the parent entity of the field, in your case the paragraph, from the field object $items.

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
  // get the parent entity of the field
  $entity = $items->getEntity();
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.