In some circumstances you might need to revert an action you just made. Especially when using the JS-Link this would be a usable feature.
A similar functionality can be seen in the Flag module. There you can "flag" a content, then the link changes to "Unflag". So you could redo your action in an easy way.
I tried out some code and finally I ended up in providing a rule action, that may set a "Rule Link for JS". This way you could call the action in any rule executed by a rules link, and so set an "inverse" Link.
One example can be two links for "publish" and "unpublish" of a node.
I'll pack the patch and an example feature in the next comment.
Comments
Comment #1
derhasi commentedThere's a patch and an example feature added.
Comment #2
mitchell commentedI tested this out and it works well. What a brilliant solution! However, isn't the configuration method a bit complex for the targeted use case? This solution strikes me as a more general and more awesome feature for advanced use cases. See #441004: Finite state machine (FSM) for issue status for a perfect example of how this could be used :)
Would it be possible to use this functionality to create a configuration method similar to Flag? Maybe one way would be to automatically create another rule when an "Add an inverse link" option is selected. Perhaps this feature could also benefit from #1280000: Replace triggering rule-sets with events.
Comment #3
Yuri commentedAfter installing the example feature and patch in #1 , for me it does not appear to work completely:
The rules link label indeed switches from 'Unpublish' to 'Publish' after pressing it. But after refreshing the page, the link label appears empty, and thus is not remembered.
Can you verify that this indeed the case? Thanks.
Comment #4
Yuri commentedAnyone?