You are here

function focal_point_field_attach_presave in Focal Point 7

Implements hook_field_attach_presave().

File

./focal_point.module, line 278

Code

function focal_point_field_attach_presave($entity_type, $entity) {
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // Check every field as its data is being inserted and if it has focal point
  // support, save the focal point data.
  foreach (field_info_instances($entity_type, $bundle) as $instance) {
    $field_name = $instance['field_name'];
    if (_focal_point_supported_widget_type($instance['widget']['type'])) {
      $images = array();
      try {
        $wrapper = entity_metadata_wrapper($entity_type, $entity);
        $images = $wrapper->{$field_name}
          ->value();
      } catch (EntityMetadataWrapperException $e) {
        watchdog_exception('focal_point', $e);
      }
      if (!empty($images) && is_array($images)) {
        _focal_point_images_save($images);
      }
    }
  }
}