By Summitt Dweller on
I have a one-time operation that I'd like to apply to a selection of a few hundred nodes. So, I'm thinking this looks like something Views Bulk Operations can deal with, and I'm sure it can.
The specific task is to update a couple of CCK fields in that collection of nodes. So, how do I code the body of an "Execute arbitrary PHP script" to do this?
In my first attempt I did this... but it failed to do anything more than confirm what the elements of $object look like.
print_r( $object );
$object->field_profile_courtesy_title = "Ms.";
node_save( $object );
Anybody here able to put me on the right path again? Thanks.
Comments
Found My Own Answer
Like any "Action" the "arbitrary PHP script" needs to act on the database directly in order to make changes. Even though $object is passed by reference (so it's writable...this really had me confused) there's apparently nothing going on downstream to save any changes you make to $object.
What I ended up coding was something simple like...
Worked nicely.
If the
If the
field_profile_courtesy_titleis a CCK field, then you should probably set it as such:because that's the way CCK usually handles its fields.
Use node_load first
I was able to get this to work by loading my own node object using the node_load function and the $object->nid. Here is the code I placed in the PHP script to update the file description for a CCK filefield.
Thanks for asking the question in the first place though and posting your own solution. It certainly helped me find this solution.
And you'll probably need to
$object is the node
you only need to do
This code not worked in
This code not worked in Drupal 7 with additional fields
In D7, you need to use the
In D7, you need to use the Field API.
Can you write simple example?
Can you write simple example?
D7 examples of PHP in VBO
some working D7 examples here: http://drupal.org/node/1000200
Make the pHp code sticky , so i dont have to enter it again ..
I needed to do the same thing, i.e. execute PHP snippet in VBO. I finally figured it out, thanks to this thread and it is working just fine.
For beginners, install VBO module, then go to your view, build it. Under basic setting set the Style to "Bulk Operations" Then you can choose selected operations you want the VBO to do for you.
Now my question: is there a way to make the php snippet to stick so I dont have to enter it every time.
I eventually like to hide the php form box so my admin user wont see it.
Thanks
Tom
Sticky PHP action
To make your script sticky on D6:
* go to admin/settings/actions/manage
* find the "Make a new advanced action available" downdown
* select the "Execute arbitrary PHP script..." action
* click "Create"
* In the new page, rename the action to something specific and write your script
* click "Save"
* go back to your VBO admin page
* select the new action you just created
When you execute this action, the PHP form will no longer appear because it's using the script you entered.
Hope this helps!
sticky PHP
Thanks very much infojunkie . Your comment was god sent. Spent a trying to figure the last part.
Thanks
Tom
sticky php action
Is the process in drupal 7 similar?not sure how to add the action to vbo. Any suggestions?
Many Thanks
I would try to use the Rules
I would try to use the Rules module
Edit the view
You can add the action in the settings for the VBO field.
Awesome!
Thank you!