I have a view with nodes and a views bulk operations field. With this vbo field I like to "modify entitity values" of the selected node.

Is it possible:

  • to automatically check the checkbox for a selected field, so that the field to modify the value is shown by default?
  • to automatically set a default value in the textfield (which should be shown by default of course)?

You have to hook the form, which is shown after clicking "Modify entity values".

Here is my code to handle this:

 * Implements hook_form_alter().
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {

  global $user;
  $account = user_load($user->uid);

  //to get the form id, you have to print it out first

  switch ($form_id) {
    case 'views_form_your_view_display_name':

      $nid_page = menu_get_object();

      // the next line activates the checkbox to show the input field
      $form['bundle_item']['show_value']['field_name']['#default_value'] = TRUE;

      // the next line sets the default value for the field shown
      // notice: the 'value' array field depends on the field type and may also
      // be 'target_id' (for entity references) or 'tid' for taxonomy references
      $form['bundle_item']['field_name'][LANGUAGE_NONE][0]['value']['#default_value'] = $your_desired_value;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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