-1

I am trying to override a VBO field in order to add a label.

In the following code, preg_match() returns an empty array and var_dump($output) returns a 41-character string, which is wrong.

print $output;
preg_match ("/id=\"(.*)\"/si", $output, $matches); 
print_r ($matches);

The content of $output is the following.

<div class="form-item form-type-checkbox form-item-views-bulk-operations-11">
<input class="vbo-select form-checkbox" type="checkbox" id="edit-views-bulk-operations-11" name="views_bulk_operations[11]" value="12">
</div>

How do I add a label to the field?

6
  • I'm not sure what your problem is here. Is this a problem with the regular expression? How are you trying to override the vbo field? Are you using hook_form_alter? You should provide more information about the Drupal part of the problem
    – F1234k
    Commented Sep 19, 2014 at 3:03
  • this is a problem with the variable $output i believe. Im tring to override views theme with an extra file views-view-field--block--views-bulk-operations.tpl.php. Regular expression is not working on the variable $output. If I copy the rendered contents and redeclare the variable like $output="<div class="form-item form...."; regular expresion works fine
    – hostdog
    Commented Sep 19, 2014 at 15:49
  • Some random ideas: did you print the contents of the $output variable just before using the preg_match function (it may not be populated at this stage yet)? Is it properly formatted? Did you assign the result of the preg_match to the $output variable? In any case you need to show us the code as is in the specific part of the .tpl.php file...
    – F1234k
    Commented Sep 19, 2014 at 16:07
  • the code is exactly as it is quoted in my first post, the variable's "content as appear in the dom source" after print as well
    – hostdog
    Commented Sep 19, 2014 at 16:45
  • Are you sure that the code that you are viewing in your html page is actually the one that is printed by the print $output command? Can you try enabling the devel module and do a dpm($output) instead of just printing it in the tpl.php file? Sorry for insisting on this, but preg_match is a PHP function and it just can't be not working. You need to make sure that you are passing the write content to it for matching. Do something along the lines of: dpm($output); preg_match ("/id=\"(.*)\"/si", $output, $matches); dpm($matches); and show us the results.
    – F1234k
    Commented Sep 19, 2014 at 17:37

1 Answer 1

1

If you just want to add a label, instead of going to the hook_form_FORM_ID_alter and figuring which fields need to change and how, you should first check the options that are already available in Views and allow you to change your field's styling. Specifically, you can edit the Bulk Operations field:

Edit Bulk Operations field link

and search for the Style Settings:

Style Settings Options

A sample configuration may look like this:

Views Bulk Operations Field Sample Style Configuration

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.