I have done the following more than once in my module now:

$fields = FillPdfFormField::loadMultiple(
    ->condition('fillpdf_form', $entity->id())

fillpdf_form_field.fillpdf_form is an entity reference field pointing at a FillPdfForm. One form can have many fields.

I want to refactor this out into its own helper. My first thought is to do it in a service (because I need to inject QueryFactory), but I wasn't sure if there was a more clever place to put it. I also couldn't find a generic "load referencing entities" method anywhere.

  • EntityReference field already has method for this. See \Drupal\Core\Field\EntityReferenceFieldItemList::referencedEntities()
    – user21641
    Commented Nov 17, 2015 at 14:07
  • @IvanJaros Yeah, that will let me load the FillPdfForm from the form field but not the other way around because the reference is from child to parent, not parent to child. Commented Nov 17, 2015 at 14:49


Your Answer

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

Browse other questions tagged or ask your own question.