1

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

<?php
$fields = FillPdfFormField::loadMultiple(
  $this->entityQuery->get('fillpdf_form_field')
    ->condition('fillpdf_form', $entity->id())
    ->execute());

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.

2
  • EntityReference field already has method for this. See \Drupal\Core\Field\EntityReferenceFieldItemList::referencedEntities()
    – user21641
    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. Nov 17, 2015 at 14:49

0

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.