You are here

function _commerce_file_field_unserialize_data in Commerce File 7

Converts saved commerce_file field data columns back to arrays for use in the rest of the current page request execution.

Parameters

$entity_type: The entity type variable passed through hook_field_attach_*().

$entity: The entity variable passed through hook_field_attach_*().

2 calls to _commerce_file_field_unserialize_data()
commerce_file_field_attach_insert in includes/commerce_file.field.inc
Implements hook_field_attach_insert().
commerce_file_field_attach_update in includes/commerce_file.field.inc
Implements hook_field_attach_update().

File

includes/commerce_file.field.inc, line 231
Implement an commerce_file field, based on the file module's file field.

Code

function _commerce_file_field_unserialize_data($entity_type, $entity) {

  // Loop over all the commerce_file fields attached to this entity.
  foreach (_commerce_file_get_commerce_file_fields($entity_type, $entity) as $field_name) {

    // Iterate over the items arrays for each language.
    foreach (array_keys($entity->{$field_name}) as $langcode) {
      $items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();

      // For each item in the array, unserialize or initialize its data array.
      foreach ($items as $delta => $item) {

        // If we have a non-array $item['data'], unserialize it.
        if (!empty($item['data']) && !is_array($item['data'])) {
          $entity->{$field_name}[$langcode][$delta]['data'] = unserialize($item['data']);
        }
        elseif (empty($item['data'])) {
          $entity->{$field_name}[$langcode][$delta]['data'] = array();
        }
      }
    }
  }
}