You are here

function multifield_field_attach_submit in Multifield 7.2

Same name and namespace in other branches
  1. 7 multifield.field.inc \multifield_field_attach_submit()

Implements hook_field_attach_submit().

File

./multifield.field.inc, line 271
Field integration for the Multifield module.

Code

function multifield_field_attach_submit($entity_type, $entity, $form, &$form_state) {
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  $multifields = multifield_get_fields();
  $instances = array_intersect_key(field_info_instances($entity_type, $bundle), $multifields);
  foreach (array_keys($instances) as $field_name) {
    $machine_name = $multifields[$field_name];
    if (!empty($entity->{$field_name})) {
      foreach ($entity->{$field_name} as $langcode => &$items) {
        foreach ($items as $delta => &$item) {
          $pseudo_entity = _multifield_field_item_to_entity($machine_name, $item);

          // @todo Ensure that $pseudo_entity->original is available.
          // Run each sub-field through hook_field_submit().
          _multifield_field_invoke_default('submit', $machine_name, 'multifield', $pseudo_entity, $langcode, $form, $form_state);

          // Run each pseudo-entity through hook_field_attach_submit().
          foreach (module_implements('field_attach_submit') as $module) {
            $function = $module . '_field_attach_submit';
            $function('multifield', $pseudo_entity, $form, $form_state);
          }
          $item = _multifield_field_entity_to_item($pseudo_entity);
        }
      }
    }
  }
}