You are here

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

Maps PMP doc attributes to entity fields.

Parameters

object $entity: Any drupal entity object

object $doc: A PMP doc

array $map: A mapping of PMP profile attributes (etc.) to entity fields

1 call to PMPAPIDrupalPull::mapFields()
PMPAPIDrupalPull::saveEntity in pmpapi_pull/classes/PMPAPIDrupalPull.php
Saves a PMP doc as an entity.

File

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

Class

PMPAPIDrupalPull
Turns PMP hypermedia docs in Drupal entities.

Code

function mapFields($entity, $doc, $map, $label) {
  $info = pmpapi_get_profile_info($doc->profile);
  $pmp_label_field = $label ? array_search($label, $map) : NULL;
  foreach ($map as $pmp_field => $local_field) {
    $pmp_info = $info[$pmp_field];
    $pmp_type = $pmp_info['type'];
    if (!empty($doc->attributes->{$pmp_field}) && $local_field !== '0' && $pmp_type != 'item') {
      if ($pmp_field == $pmp_label_field) {
        $this
          ->mapLabel($entity, $doc, $label, $pmp_label_field);
      }
      else {
        $this
          ->mapAttribute($entity, $doc, $local_field, $pmp_field, $pmp_type);
      }
    }
  }
}