You are here

function title_field_attach_submit in Title 7

Implements hook_field_attach_submit().

Synchronize submitted field values into the corresponding legacy fields.

File

./title.module, line 627

Code

function title_field_attach_submit($entity_type, $entity, $form, &$form_state) {
  $fr_info = title_field_replacement_info($entity_type);
  if (!empty($fr_info)) {

    // We copy (rather than reference) the values from $form_state because the
    // subsequent call to drupal_array_get_nested_value() is destructive and
    // will affect other hooks relying on data in $form_state. At the end, we
    // copy any modified value back into the $form_state array using
    // drupal_array_set_nested_value().
    $values = $form_state['values'];
    $values = drupal_array_get_nested_value($values, $form['#parents']);
    $langcode = entity_language($entity_type, $entity);
    foreach ($fr_info as $legacy_field => $info) {
      if (!empty($form[$legacy_field]['#field_replacement'])) {

        // Give a chance to operate on submitted values either.
        if (!empty($info['callbacks']['submit'])) {
          $info['callbacks']['submit']($entity_type, $entity, $legacy_field, $info, $langcode, $values);
        }
        drupal_static_reset('field_language');
        title_field_sync_get($entity_type, $entity, $legacy_field, $info, $langcode);
      }
    }
    drupal_array_set_nested_value($form_state['values'], $form['#parents'], $values);
  }
}