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;
}
CommentFileSizeAuthor
#1 container_labels.patch570 bytesIsland Usurper

Comments

Island Usurper’s picture

Component: User Interface » User interface
Status: Active » Needs review
StatusFileSize
new570 bytes

It 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.

Status: Needs review » Needs work

The last submitted patch, container_labels.patch, failed testing.

Island Usurper’s picture

I 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.

Island Usurper’s picture

Status: Needs work » Needs review

#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.

Status: Needs review » Needs work

The last submitted patch, container_labels.patch, failed testing.

Island Usurper’s picture

WTF? Under "Review log":

[12:51:10] Main branch [drupal] checkout complete.
[12:51:14] Dependency [curlypage] checkout complete.
[12:51:17] Dependency [rules] checkout complete.

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?

Island Usurper’s picture

Status: Needs work » Needs review

#1: container_labels.patch queued for re-testing.

fago’s picture

Great, 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.

Island Usurper’s picture

Status: Needs review » Active

OK, yes loading the component with rules_config_load() does mean that the label is available.So the problem lies somewhere in the UI.

fago’s picture

Status: Active » Fixed

Indeed. I fixed it by adding a 'label' column to the rules_config table.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.