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