1

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?

1 Answer 1

2

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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