I had set up some condition sets in hook_default_rules_configuration(), but had forgotten to give them meaningful labels. I didn't want to revert the conditions I had added through the form, but I found the components page in the admin UI. However, whenever I tried to change the label in the settings, the new label was never saved to the database. The UI always lists them as "AND".
I also found that even after reverting, the labels were still "AND". Maybe I'm not setting it right, but I can't find any other way. Here's the hook_default_rules_configuration() I'm using:
function uc_quote_default_rules_configuration() {
$configs = array();
$methods = module_invoke_all('uc_shipping_method');
foreach ($methods as $method) {
$set = rules_and(array(
'order' => array('type' => 'uc_order', 'label' => 'Order'),
));
$set->label = t('%method conditions', array('%method' => $method['title']));
$configs['get_quote_from_' . $method['id']] = $set;
}
return $configs;
}
Comments
Comment #1
Island Usurper commentedIt seems like the labels aren't being saved along with the conditions because __sleep() doesn't include 'label' for Ands and Ors. Even if this is deliberate, it's still confusing to have a field that looks like it should change it in the settings.
Rules and rule sets are probably what I'm expected to use, but I want to make sure the user doesn't change the actions that happen when the conditions are met. I'm not even sure I want more actions to be added in this place in the workflow because it's only calculating a value rather than performing an action.
Here is a patch for RulesConditionContainer::__sleep() that saves the label if it has been set.
Comment #3
Island Usurper commentedI don't know what error it's choking on, and my laptop isn't running the tests with any kind of speed. I'll see if I can get any results tonight, but I might have to let someone else have this one.
Comment #4
Island Usurper commented#1: container_labels.patch queued for re-testing.
All tests passed on my machine (after more than 2 hours!), so I'm still not sure what's broken.
Comment #6
Island Usurper commentedWTF? Under "Review log":
Why is curlypage and not entity being checked out during testing? How are the tests being run when the module shouldn't be able to be installed?
Comment #7
Island Usurper commented#1: container_labels.patch queued for re-testing.
Comment #8
fagoGreat, it looks like the test bot is back to work.. ;)
>Rules and rule sets are probably what I'm expected to use
You are using it perfectly fine and your use-case makes sense. Everything marked as 'component' in rules_rules_plugin_info() is supposed to be re-used, so are condition sets.
However labels usually don't get serialized with the objects, but added on load, see RulesEntityController::attachLoad(). Therefore it should work without having it in sleep(). Also sleep doesn't play a role when you are using the default hook, so perhaps something else is wrong here? Also your uc_quote_default_rules_configuration() looks good to me.
-> Thus is the label properly there when you manually load the config using rules_config_load('name')? Does label() return it? If yes, then the problem lies in the UI.
Comment #9
Island Usurper commentedOK, yes loading the component with rules_config_load() does mean that the label is available.So the problem lies somewhere in the UI.
Comment #10
fagoIndeed. I fixed it by adding a 'label' column to the rules_config table.