Skip to content

Instantly share code, notes, and snippets.

View jpmc's full-sized avatar
🗲

James Corrao jpmc

🗲
  • Quotient inc.
  • Maryland
View GitHub Profile
@jpmc
jpmc / Drupal8_GetEntityRef.php
Last active March 16, 2018 13:15
A uniform method for getting Entity Reference(s) from Entity fields of varying cardinalities.
<?php
/**
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* Entity that has fields.
* @param String $field_name
* Field name for Entity Reference field.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* Return an array of one or more referenced entities.