You are here

function PMPAPIDrupalPull::reference_exists in Public Media Platform API Integration 7

Determines if an entity already references an entity id.

Parameters

$entity object: A Drupal entity

$field_type string: The type of reference field

$field string: The name of the reference field

$eid: The id of the entity being referenced

Return value

boolean TRUE if entity references the entity id, FALSE otherwise

1 call to PMPAPIDrupalPull::reference_exists()
PMPAPIDrupalPull::addItems in pmpapi_pull/classes/PMPAPIDrupalPull.php
Maps PMP doc items to entity fields.

File

pmpapi_pull/classes/PMPAPIDrupalPull.php, line 491
Contains PMPAPIDrupalPull.

Class

PMPAPIDrupalPull
Turns PMP hypermedia docs in Drupal entities.

Code

function reference_exists($entity, $field_type, $field, $eid) {
  if (!empty($entity->{$field}[$entity->language])) {
    $key = $field_type == 'entityreference' ? 'target_id' : 'fid';
    foreach ($entity->{$field}[$entity->language] as $reference) {
      if (isset($reference[$key]) && $reference[$key] == $eid) {
        return TRUE;
      }
    }
  }
}