I wanted to get rid of the fieldset around operations. In order to do this I needed to form_alter the same as what VBO does, and set the module weight below VBO's. This is a bit odd. It would be better if views_bulk_operations_form were alterable directly.

Just a minor feature request. I will write a patch for this and submit it later.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Sure, why not.

mradcliffe’s picture

Assigned: mradcliffe » Unassigned
Status: Active » Needs work
FileSize
1000 bytes
1.44 KB

I was looking at either drupal_get_form, drupal_build_form, or drupal_rebuild_form. I ended up trying to work with drupal_build_form, but I lost the operation value on submit. I might need to analyze and change $form_state a bit more. Also tried working on a test file/module using admin_content default vbo view.

It probably isn't worth posting what I have, but I will in case anyone else wants to work on it.

bojanz’s picture

Title: views_bulk_operations_form should be called via drupal_get_form so it can be altered » It is hard to alter the VBO form
Status: Needs work » Active

Yeah, that is definitely a bad idea.

So, we either document that in order to modify a VBO form you need to do:

function hook_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'views_form_') === 0) {
    $vbo = _views_bulk_operations_get_field($form_state['build_info']['args'][0]);
  }
  // Not a VBO-enabled views form.
  if (empty($vbo)) {
    return;
  }

  if ($form_state['step'] == 'views_form_views_form') {
    // This is the initial step of the VBO form. Do what you need to do.
  }
}

Or maybe add a hook_views_bulk_operations_form_alter().

Thoughts?

mradcliffe’s picture

Sorry for not replying, bojanz. This thread slipped my memory. I think that's suitable documentation for now, but maybe in 6 months we can look at doing hook_views_bulk_operations_form_alter().

Another quirk. If you do funky things like disabling checkboxes, it really confuses VBO and actions. Although I think that's more related to the js stuff. :-)

Edit: What's the plan for the book structure at http://drupal.org/node/335694? I'll start documenting there with a bit of guidance.

bojanz’s picture

I can't seem to edit that page for some reason.

tomas.teicher’s picture

I cannot get it work. How can I edit vbo form in my hook_form_alter?
In particular, I want to edit form in that way, that I would have my custom submit function (with my custom submit button). But I cannot do it because selecting vbo operation in operations fieldset is required.
But I cannot edit the fieldset in form hooks.
Is it possible to achieve this without a patch?

bojanz’s picture

You need the code in #3.
You also need to make sure your module runs after views_bulk_operations.
So if views_bulk_operations has a weight of "0", your module needs to have at least the weight of 1.
Weight is a column in the {system} table (though there's probably a contrib module that handles it as well).

tomas.teicher’s picture

thanks it works OK

Tomas

damiankloip’s picture

I think add a hook_views_bulk_operations_form_alter hook makes alot of sense. I have done something similar in textformatter now, it makes things alot easier for people altering, and saves a few support queries too :)

@bojanz - Do you want a patch for this?

bojanz’s picture

Yes, please!

damiankloip’s picture

Status: Active » Needs review
FileSize
1.25 KB

Here is an initial patch for this, I'm not sure if this covers everything we need right off the bat but should be a good start.

damiankloip’s picture

FileSize
1.22 KB

With a newline at the end of the api.php file

bojanz’s picture

Title: It is hard to alter the VBO form » Add hook_views_bulk_operations_form_alter().
FileSize
1.95 KB

How about this version?

bojanz’s picture

Status: Needs review » Fixed

Committed a tweaked version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.