You are here

function wshybridfield_field_formatter_prepare_view in Web Service Data 7

Implements hook_field_formatter_prepare_view().

File

modules/wshybridfield/wshybridfield.module, line 153

Code

function wshybridfield_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {
  $element = array();
  foreach ($items as $entity_id => $field_items) {
    foreach ($field_items as $delta => $settings) {
      $wsconfig_method = explode(':', $settings['wsconfig_method']);
      $wsconfig = wsconfig_load_by_name($wsconfig_method[0]);
      $method = $wsconfig_method[1];
      if (!is_object($wsconfig)) {
        $items[$entity_id][$delta]['wsdata_error'] = t('Unable to load WSConfig @wsconfig', array(
          '@wsconfig' => $wsconfig_method[0],
        ));
        continue;
      }
      $replacements = json_decode($settings['replacements'], TRUE);
      $replacements = isset($replacements) ? $replacements : array();
      $arguments = json_decode($settings['arguments'], TRUE);
      $arguments = isset($arguments) ? $arguments : array();
      $options = json_decode($settings['options'], TRUE);
      $options = isset($options) ? $options : array();
      $data = $wsconfig
        ->call($method, $replacements, $arguments, $options);
      $items[$entity_id][$delta]['wsdata'] = $data;
    }
  }
}