You are here

function editablefields_filefield_js in Editable Fields 6.3

If the Remove button was clicked remove the file from the node.

1 string reference to 'editablefields_filefield_js'
editablefields_menu_alter in ./editablefields.module
Implementation of hook_menu_alter().

File

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

Code

function editablefields_filefield_js($type_name, $field_name, $delta) {
  if (!empty($_POST['editablefields_node_nid']) && ($node = node_load($_POST['editablefields_node_nid']))) {
    $remove_button_clicked = FALSE;
    foreach ($_POST as $key => $value) {

      // check if the remove button was clicked
      if (stripos($key, $field_name) === 0 && stripos($key, '_filefield_remove') !== FALSE) {
        $remove_button_clicked = TRUE;
        break;
      }
    }
    if ($remove_button_clicked) {
      $field = $_POST[$field_name];
      $field = array_pop($field);
      $file = (object) field_file_load($field['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,
        ));
      }
      $file->field_name = $field_name;
      $references = field_file_delete($file);
      $node->{$field_name}[$delta] = array();
      node_save($node);
      drupal_set_message(t('File %filename was removed from node.', array(
        '%filename' => $file->filename,
      )));
    }
  }
  filefield_js($type_name, $field_name, $delta);
}