In some projects I have had the need to take multiple arguments in rule sets to be able to perform the needed task. Some examples of these task are:
* Select content to add as relations to a node given as argument in the view
* Alter the author of the selected nodes to be the author of the first commenter on the node
Some times the data to be provided as parameter in the rule set comes from an argument on the view and sometimes the data comes from a views relation.
The patch provided below adds the possibility to provide parameters declared as primitives on the rule set on the vbo operation field settings page. Provided parameters will be hidden on parameter input from if there are some parameters to be provided on the execution of the operation.
The functionality was almost possible to implement without altering the api. I did however need to provide the vbo field as a constructor argument on the operation_types plugin to be able to look at the current state of the view during execution. Feedback and suggestions to make this in a more efficient way will be highly appreciated.
Comments
Comment #1
auth CreditAttribution: auth commentedPatch attached
Comment #2
auth CreditAttribution: auth commentedAttaching new version of the patch. Because I could not get row data to work properly the new functionality is limited to passing arguments to the rule set.
Comment #3
wickwood CreditAttribution: wickwood commentedI tried using the patch from #2 but I don't see anything to configure my VBO to use the new functionality and now my view does not show the selected VBO action under operations.
If you can tell me how to use this, that would probably solve my problem. Also, I don't know what I can do to help, but if I can I will. I also need this functionality.
All the Best,
Steve
Comment #4
wickwood CreditAttribution: wickwood commentedEven after removing the patched VBO module the VBO action buttons are not rendering.
I'm using Aegir and thus have have a multisite environment. I had installed the patched VBO module in the /sites/site/modules/ directory to override the VBO module in /sites/all/modules/ directory.
I've disabled and re-enabled the module cleared caches, but it still nothing.
Comment #5
wickwood CreditAttribution: wickwood commentedI cloned my site to a development domain and the problem I described before was corrected. Something must have been saved that I couldn't otherwise clear. I couldn't totally uninstall VBO as I didn't want to lose configuration from other modules that use it too.
Comment #6
lunk rat CreditAttribution: lunk rat commentedLike wickwood I patched 7.x-3.x-dev with the patch in #2, but I do not see any new configuration options on my VBO field for my rules components.
Is there a further trick to get this to appear?
Comment #6.0
lunk rat CreditAttribution: lunk rat commentedRemoved a use case since it is rather easy to accomplish already. Feeding arguments as parameters is still a new very useful feature though.
Comment #7
wickwood CreditAttribution: wickwood commentedAfter searching and searching, this patch seemed to be the only thing that I've found to do what I needed to do which was to pass an integer parameter along with each user record selected in a View with VBO to a Rules Component.
What I apparently was doing wrong before was I was not defining the Views Contextual Filter before looking for a change in the VBO configuration. Once I did this a "Provide parameters" option was available where I could select my Views Contextual Filter for the appropriate 2nd argument for the VBO Rules Component.
In my case since I don't really need the Views Contextual Filter I configured the Views Contextual Filter to be
Global:Null
.Hope this helps someone. This has been driving me nuts for months!!!
Steve
P.S. Thanks again Auth for creating the patch. I hope it gets added to VBO. It could solve a lot of headaches. I surprised more people don't need this. Now that I know how to do this I can see all kinds of uses for it.
Comment #8
auth CreditAttribution: auth commentedThank you for all your feedback. There are a few conditions which needs to be fulfilled in order for the new options to show up.
* Create a new rule set with a minimum of 2 parameters. The first should as before be of the same entity type as the view. The second and up must be of type decimal, integer or text.
* Add the bulk operations field to your view and select your rule set as an action
* Check the "Provide parameters" checkbox
* To have options in the paramaters dropdown add contextual filters to the view
A new patch (views_bulk_operations-add-view-data-as-parameters-to-rule-set-1967702-3.patch) that should apply cleanly to the latest dev is provided.
I would appreciate if someone with more experience with the issue queue would look at this and make sure this issue is in an appropriate state.
Comment #9
auth CreditAttribution: auth commentedComment #10
jgullstr CreditAttribution: jgullstr commentedI used this to create a view that allows you to assign users to an entityreference field in a node provided by a contextual filter. Works great - just what I needed.
You have some whitespace errors in your patch:
I'm not very familiar with the inner workings of the VBO module, but I will try and review the code in the following days. Thank you for your contribution!
Comment #11
tchopshop CreditAttribution: tchopshop commentedI'm not sure if this patch is what I need, or if I'm just configuring things wrong.
I am trying to create a VBO of users filtered by a taxonomy term reference on the user entity. The VBO should live on a page tab off the taxonomy term.
I'd like to have the rule component create a new entity (node) and populate it with all the users selected in the VBO plus add the taxonomy term argument that is filtering the view.
Comment #12
auth CreditAttribution: auth commentedThat sounds like something this patch definitely should be able to help you with.
Create the rule set with two parameters. The first one of the type user and the second one of type integer. Name the parameters as you like but for this example I named the user "param_user" and the integer "param_term_tid". In the rule set you load the real term object using "load entity" of type taxonomy term with param_term_tid as the entity id. Then you can configure your rule set to do the task you want using the user and the term.
In your bulk operations view it is important you provide a contextual filter with the term id in some way. I usually build my sites using panels which makes it easy to provide the value for the filter per pane or from a panels context. If you build the view using a page display directly you should be able to add the argument from the url or even hard code it using the Global: null argument type. Then on your bulk operations field you include your rule set with two parameters and check "Provide parameters" and the parameter "param_term_tid" should be configurable.
I hope this will take you closer to you goal.
Comment #13
tchopshop CreditAttribution: tchopshop commentedthank you so much, that helps!
Comment #14
nimek CreditAttribution: nimek commentedWhen it will be added to official release ???
Comment #15
nevergone CreditAttribution: nevergone commentedNot possible apply the #9 patch. Please re-rolled on the HEAD.
Comment #16
lunk rat CreditAttribution: lunk rat commentedTrying to patch #9 against 3.x-7.x-dev and Hunks #6 and #7 fail:
And the rej file:
A re-roll would be much appreciated. Thanks for this patch!
Lunk
Comment #17
marcusx CreditAttribution: marcusx commentedGreat! Exactly what I needed.
Here is a rerolled patch against latest HEAD.
Comment #18
lunk rat CreditAttribution: lunk rat commentedThanks marcusx patch #17 works against 7.x-3.x-dev
Comment #19
wickwood CreditAttribution: wickwood commentedPatch in #17 applied with whitespace warnings
Applied this to the last commit on 12/23/2013 which has SHA ID:1796c1dbad033e41f5addfb8da0f159cf11c44e4
Comment #20
dojorob76 CreditAttribution: dojorob76 commentedI had the same issue as wickwood, which then continued...
After applying the patch and attempting to add VBO Content to a view, I received several errors. Here are the messages from my log report:
This was patched against the latest dev version of VBO, updated 2014-Feb-10
(Running Drupal 7.26, PHP 5.3.10)
Comment #21
tedbowI am having the same problem as #20
The problem is that patch in #17 does not contain all the changes from the patch in #9
This will only work if views_bulk_operations_get_operation
and other changes from the #9 patch are also applied.
$operations[$operation_id] = new $plugin['handler']['class']($operation_id, $entity_type, $operation_info, $options);
Doesn't pass the $operationsField so that is why you get the error " Trying to get property of non-object in "
I suspect the only reason that it was working for some people is that had already applied on of the previous patches. The patch needs to be re-rolled to include all changes from #9.
Comment #22
tedbowOK here is patch re-rolled with the changes from #9 included also.
Also ran the patch through Coder. This is always a good idea so that it is more likely to be adopted by the module maintainers and to save them time.
Also I like the idea but I think limiting the values you can pass to the Rule to only the parameters of View is limiting.
If you instead used the regular "Replacement Patterns" for the View Row then you would be able pass not only the Views contextual filter values but also the values for other fields on the Row.(unless I am missing something this can't be done by the current patch.
Comment #23
dojorob76 CreditAttribution: dojorob76 commentedThank You, tedbow. I just applied and tested your patch from #22, and it appears to be working great.
The "provide parameters" option showed up in my VBO form as it should, the rule and operation fired off perfectly, and there were no error messages to report.
Thanks for catching that problem and rolling the new patch. Much appreciated.
Comment #24
auth CreditAttribution: auth commentedUnfortunately I have not had much time to work on this patchs recent months feedback so I really appreciate the great work from the other contributors. The initial ambition was to provide something similar to the regular replacement selector but the architecture of vbo prevented me from hooking up to anything other than the rows entity. Just providing support for arguments solved the need to reuse vbo views for multiple purposes and since rules can load related data the functionality can in most cases be implemented there instead. Keep up the awesome work everyone!
Comment #25
lunk rat CreditAttribution: lunk rat commented@tedbow this patch works great, thank you.
Comment #26
Yuri CreditAttribution: Yuri commentedI tested the patch #22 this week, and it appeared to work sometimes. I figured out that the problem is with panels and using panel context in the view panes.
I'm using in a view Global Null to get the current node ID for the integer parameter in a rules component.
The obvious approach would be: In the view, in Pane settings, Argument input, I set Global: Null source to "from context" with "Content ID"
However, that is not recognized as a parameter in Rules.
On the other hand, when in the view I set the Argument input as "Input on pane config", and in the Panel pane config I insert %node:nid, then Rules does recognize it as a parameter.
Comment #27
Yuri CreditAttribution: Yuri commentedI have noticed another issue: that the 'Provide parameters' in VBO settings changes its value when the contextual filters are rearranged in the view.
Comment #28
fox_01 CreditAttribution: fox_01 commented#22 is working for me but sometimes when i update the rules component the "provide parameters" form resets to "none"
Comment #29
kopeboy CreditAttribution: kopeboy commentedThis would be very useful! I would like to help but I am not a developer.. please review and include it!
This would eliminate the need of a lot of entity reference fields on the entities and a lot of conditions (loading fields etc.) in the rules, thus making them lighter and faster!
Comment #30
wickwood CreditAttribution: wickwood commentedI just realized that I never reported back that patch 22 has been working for us. We haven't had any issues that we are aware of.
Comment #31
jweirather CreditAttribution: jweirather commentedWhich version of the module should I be using for a clean apply of the #22 patch? I tried the most recent 7.x-3.x-dev, but had a fail on a hunk. I tried to apply that hunk manually, but the rule isn't seeing the argument so it's still prompting me for the value that I'm trying to populate automatically, and I'm assuming something got lost in the mix. Here's the reject from the hunk fail:
Is there a version I can install from drush that already has the patch? Or one I can install and then apply the patch cleanly?
And a HUGE +1 for this feature. I'm surprised it isn't part VBO already.
Thanks!
Comment #32
mollux CreditAttribution: mollux commentedPatch in #22 wasn't working for me, as I have a rule which has non-primitive input parameters, so I couldn't configure the vbo settings.
Also the data wasn't passed correctly to the executeByArgs() function.
I rerolled the patch to work wit the latest dev version, removed the primitive parameter requirement and cleaned up the code to follow Drupal Coding standards.
Comment #33
delphinx CreditAttribution: delphinx commentedGreat patch. Thanks for sharing. One question though: Although I've selected "Skip confirmation step" in settings, I still get a page with "Next" "Cancel" after clicking the button that triggers the rules component. It doesn't immediately process the selected items as what I would expect when selecting "Skip confirmation step". When I enable this option, I'm asked twice to confirm. Is this by design or am I missing a setting somewhere? I'm using VBO 7.x-3.3.
Comment #34
lelivero CreditAttribution: lelivero as a volunteer commentedI experience the same issue as delphinx. In my mind I didn't have this issue with patch #22 and a previous dev version of VBO. I haven't tested that yet though. I'm using 7.x-3.3+2-dev (2015-Nov-28)
Comment #35
ibuildit CreditAttribution: ibuildit commentedIt would be very very very useful to be able to include any field in the current view in the format of regular replacement tokens! :)
Comment #36
Yuri CreditAttribution: Yuri commentedAlthough it works, the issue is still present mentioned in #33 and #34, the 'Next / Cancel' page shows up even if 'skip confirmation step' is selected. This was not happening in the first patch versions.
Comment #37
netw3rker CreditAttribution: netw3rker commentedIt looks like @mollux's update in #32 was a little aggressive in cleanup and removed the 'configurable()' method for the ViewsBulkOperationsRulesComponent class. When I brought that in, it still didn't work for me, but only because for my particular component rule there were 0 primitive parameters. What should happen here is, this rule should be marked as "not configurable" when the following conditions are met:
1) there are no primitive parameters
2) there aren't enough advanced supplied parameters for the list of required providable parameters.
Item number 1 appeared to be missing from the conditions for this, so I updated the return false conditions to ensure that if parameters are provided, and none are primitive, this gets correctly expressed as non configurable. once this happened, everything worked as expected.
Attached is a re-roll of #32 with the addition of the modified configurable implementation from #22. I would like to get some better eyes on the code I modified since it is pretty complex, and i suspect can be normalized to be a lot clearer:
Comment #38
ibuildit CreditAttribution: ibuildit commentedI'm getting this now in both dev and stable version, the argument option is no longer there.
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: http://konsult-test.dev/_www/admin/structure/views/ajax/config-item/matc...
StatusText: Service unavailable (with message)
ResponseText: ArgumentCountError: Too few arguments to function views_bulk_operations_get_operation(), 3 passed in /www/sites/konsult-test/.platform/local/builds/default/public/sites/all/modules/contrib/views_bulk_operations/views/views_bulk_operations_handler_field_operations.inc on line 203 and exactly 4 expected in views_bulk_operations_get_operation() (line 216 of /www/sites/konsult-test/.platform/local/builds/default/public/sites/all/modules/contrib/views_bulk_operations/views_bulk_operations.module).
Comment #39
ibuildit CreditAttribution: ibuildit commentedOn line 203 and 220 in views_bulk_operations_handler_field_operations.inc I added ", null" as an empty fourth parameter, that cleared the error and the parameter works again.
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options, null);
That's not the solution of course but gets me through the day. I don't think the patch got applied cleanly. I'm running 4 patches on VBO, using a makefile, so it might be related to the order the patches get applied or something.
... to be continued.
Comment #40
ibuildit CreditAttribution: ibuildit commentedIt works for me with this old version I had on another site, but not with the latest stable or latest dev.
; Information added by Drupal.org packaging script on 2015-11-28
version = "7.x-3.3+2-dev"
core = "7.x"
project = "views_bulk_operations"
datestamp = "1448719743"
Can anyone else confirm the patch from #37 is not working with latest dev or stable please?
Comment #41
maxplus CreditAttribution: maxplus commentedIndeed very nice addition to VBO.
Did not test the patch but subscribing to follow further development!
Comment #42
Yuri CreditAttribution: Yuri commentedpatch #37 gives me
Fatal error: Call to a member function get_handlers() on null in ../views_bulk_operations/plugins/operation_types/rules_component.class.php on line 45
the line mentioned is
foreach ($operation_field->view->display_handler->get_handlers('argument') as $arg => $handler) {
Comment #43
Yuri CreditAttribution: Yuri commentedRetrying patch #22 gives me Fatal error:
Cannot use object of type ViewsBulkOperationsRulesComponent as array in ../modules/views_bulk_operations/views_bulk_operations.module on line 245
which line contains: return $operations[$operation_id][$entity_type][$cid];
Comment #44
Yuri CreditAttribution: Yuri commentedI now used a vbo module from a site I made last year which included also patch #22. That works fine. So its something in VBO that has changed in the meantime which makes the patch incompatible.
Comment #45
mitjasvab CreditAttribution: mitjasvab as a volunteer commentedHi, I fixed the #37 patch against the latest dev release. It seems to work.
Please test.
Let view arguments be passed as parameters to rule set
Comment #46
junaidpv#45 works for me.
Comment #47
Joel MMCC CreditAttribution: Joel MMCC commentedThis issue was referenced through direct URL instead of the proper bracket sequence in #1291312-10: multiple arguments from VBO to Rules, so I made them both Related Issues of each other, and am including proper references.
I’ll try out Patch #45 in a bit, but have my doubts since it was rolled against the then-dev in early October of 2017, and there’s been an actual stable release since then: 7.x-3.5 dated May 8, 2018, and the current -dev is dated May 17.
Comment #48
Joel MMCC CreditAttribution: Joel MMCC commentedIt did seem to apply cleanly in 7.x-3.5. Haven’t tested against the newest -dev yet. Will try out the functionality soon.
May I suggest a UX improvement for this for Rules proper? In Components and Rule Sets, for the Variables, there’s a “Usage” column with drop-downs for “Parameter,” “Parameter + Provided,” and “Provided.” These determine input, bidirectional, and output variables, respectively. There are also columns for “Data type,” “Label,” and “Machine name” before that one.
I propose adding a new column to the right of “Usage”: “Source.” Drop-down items could be added by other modules (such as Context or Global Filter) or plugins to VBO, but would initially include “User input” (default, what it does now without this patch), “URL param #1” (through #4 or so), and perhaps some others as well.
If the “Data type” is set to a primitive such as “Date” or “Text” or “Integer,” the parameter would be assumed to be such and treated accordingly. But if it’s an Entity type such as “Node” or “User” or one provided by a contrib module such as “Group,” then the URL parameter would be treated as an Integer and a Fetch Entity by ID of that type would automatically be done on it, with the fetched entity stored in the variable instead of the ID (or null if no Entity of that type by that ID exists). Lists could be done by using comma-separated integer IDs (“21,44,135”) notation.
I figure that for now the “Source” dropdown should be disabled (grayed out) on any variable in which “Usage” is set to “Provided.” Though, maybe this concept could be extended to those as well, to specify just how they would be Provided back to Drupal.
I think I need to suggest this as a Feature Request over at Rules, don’t I?
Comment #49
Marco Aurelio Rocca CreditAttribution: Marco Aurelio Rocca commentedDoes someone know if all this marvel is working in VBO Version: 7.x-3.5??
I have just stomped on a very similar use case and it seems that my need would be satisfied by the described improvement, but I just cannot see this PROVIDE PARAMETERS checkbox nowhere, even though going through the steps detailed at #8 and somewhere else.
I still need to input manually the second parameter that I was hoping to automate.
Any help?
Comment #50
junaidpvRe-rolled patch from #45 for current 7.x-3.6.