You are here

function fb_autopost_entity_get_properties in Facebook Autopost 7

Helper function to translate from field names to property names for the SDK.

Parameters

FacebookPublicationEntity $publication: Entity to extract the properties from.

Return value

array An array of property names with their corresponding values

2 calls to fb_autopost_entity_get_properties()
FBAutopostEntity::publishEntity in fb_autopost_entity/class/FBAutopostEntity.php
Publishes content stored in a Facebook publication entity
FBAutopostEntityEvent::remoteEntityEdit in fb_autopost_entity/class/FBAutopostEntityEvent.php
Edits a publication in facebook from a stored entity. Events in Facebook can actually be updated, this means that there is no deletion needed.

File

fb_autopost_entity/fb_autopost_entity.module, line 609
Module implementation file

Code

function fb_autopost_entity_get_properties(FacebookPublicationEntity $publication) {
  $output = array();

  // By default assume the properties are like field names minus
  // 'field_facebook_'. Get all the field names associated with this entity
  // bundle.
  $field_names = array_keys(field_info_instances('facebook_publication', $publication->type));

  // We will need a entity wrapper to access the field values.
  $wrapper = entity_metadata_wrapper('facebook_publication', $publication);

  // Get a keyed array to translate field names into Facebook property names.
  $field_properties = $publication
    ->getFieldProperties($field_names);

  // Iterate over each field to fetch the actual value.
  foreach ($field_names as $field_name) {
    $value = $wrapper->{$field_name}
      ->value();
    if (isset($value)) {
      $output[$field_properties[$field_name]] = $value;
    }
  }
  return $output;
}