You are here

function editablefields_file_insert in Editable Fields 6.3

Implementation of hook_file_insert().

File

./editablefields.module, line 648
Editable fields module.

Code

function editablefields_file_insert($file) {
  if (stripos($_GET['q'], 'filefield/ahah/') === 0 && !empty($_POST['editablefields_node_nid']) && ($node = node_load($_POST['editablefields_node_nid']))) {
    $file_clone = (array) $file;
    field_file_save($node, $file_clone);
    $q_arr = explode('/', $_GET['q']);
    $field_name = $q_arr[3];
    $delta = $q_arr[4];
    $node->{$field_name}[$delta] = array(
      'fid' => $file->fid,
    );

    // respect revision settings
    $node_options = variable_get('node_options_' . $node->type, array(
      'status',
      'promote',
    ));
    $node->revision = in_array('revision', $node_options);
    if ($node->revision) {
      $node->log = t('%field_name updated by editablefields.', array(
        '%field_name' => $field_name,
      ));
    }
    node_save($node);
  }
}