5

I'm having an image field with option set as UNLIMITED to accept infinite images, basically deleting images in single manner is possible, but how it can be possible to delete multiple images at once from a particular node?

I've tried it by applying some logics using Views Bulk Operations and also using Editable Views, but nothing worked for me.

Any suggestion on this?

1 Answer 1

1

I'm a little surprised there's nothing available to empty out a field, but in its absence you can just write your own action for VBO. Contrived (and most likely incomplete) example:

function MYMODULE_action_info() {
  return array(
    'MYMODULE_delete_images' => array(
      'type' => 'node',
      'triggers' => array('any'),
      'label' => t('Remove all images'),
      'behavior' => array('changes_property'),
      'configurable' => FALSE,
      'vbo_configurable' => FALSE,

    ),
  );
}

function MYMODULE_delete_images_action($entity, $context) {
  // Pick up pre-batch config entered by user.
  $foo = $context['foo'];

  // Remove all field vals. Using 'changes_property' behavior in the
  // info hook will trigger the entity to be saved, so no need
  // to do so manually.
  $entity->field_FOO[LANGUAGE_NONE] = array();
}

function MYMODULE_delete_images_action_form($context, &$form_state) {
  // Some custom context for the batch op.
  $form['foo'] = array(
    '#type' => 'textfield',
    '#title' => t('Some option'),
  );
}

function MYMODULE_delete_images_action_form_validate($form, &$form_state) {
  // Validate the submission.
  if (bar($form_state['values']['foo'])) {
    form_set_error('foo', t('Blah'));
  }
}

function MYMODULE_delete_images_action_form_submit($form, &$form_state) {
  // Ensure submitted values are passed through to the action callback.
  return array(
    'foo' => $form_state['values']['foo'],
  );
}

Obviously you could extend the pre-batch form to allow for a choice of which field to empty, and even make this generic to all field types with a little effort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.