1

I'm declaring the varialbes of a custom module in hook_variable_info(). Now I'd like to access some of them in rules. How can I do that?

The reason for this is that the Variable module gives me the chance to added fine grained access control for this values. Otherwise I would be forced to give users full access to administer rules.

Update: I found this issue: Make Drupal variables accessible with data browser in rules To be honest I don't fully understand what it is saying.

2

As the Rules module uses tokens, and the Variable module implements hook_tokens(), you should not do anything.

If the value returned from that implementation of hook_tokens() is not the value you would expect, in a module of yours you could implement hook_tokens_alter() to alter the token values returned by the Variable module.

Reading Entity property information, I get fago means code similar to the following one should be used.

function mymodule_entity_property_info() {
  $info = array();

  // Add meta-data about the variables exposed from the Variable module.
  $properties = &$info['site']['properties'];

  // ...

  return $info;
}

I didn't find any information about the parameters passed, for example, to the setter callback, even though entity_property_verbatim_set() is defined as entity_property_verbatim_set(&$data, $name, $value, $langcode, $type, $info).

function entity_property_verbatim_set(&$data, $name, $value, $langcode, $type, $info) {
  $name = isset($info['schema field']) ? $info['schema field'] : $name;
  if (is_array($data) || (is_object($data) && $data instanceof ArrayAccess)) {
    $data[$name] = $value;
  }
  elseif (is_object($data)) {
    $data->$name = $value;
  }
}

Vice versa, entity_metadata_user_set_properties() is defined as entity_metadata_user_set_properties($account, $name, $value).

function entity_metadata_user_set_properties($account, $name, $value) {
  switch ($name) {
    case 'roles':
      $account->roles = array_intersect_key(user_roles(), array_flip($value));
      break;
  }
}

entity_metadata_user_entity_property_info() uses that setter callback in the following definition.

  $properties['roles'] = array(
    'label' => t("User roles"), 
    'description' => t("The roles of the user."), 
    'type' => 'list<integer>', 
    'getter callback' => 'entity_metadata_user_get_properties', 
    'setter callback' => 'entity_metadata_user_set_properties', 
    'setter permission' => 'administer users', 
    'options list' => 'entity_metadata_user_roles', 
    'access callback' => 'entity_metadata_user_properties_access',
  );
| improve this answer | |
  • 1
    That's waht I expected. But it doesn't work. I can see a lot of variables at admin/config/system/variable but none of them is available in rules. – BetaRide Jul 5 '12 at 14:50
  • Thanks for all the additional information! Unfortunately I'm still not sure how to move on though. Let's see whether I get a helping hand from fago or someone else how knows more about entity properties. – BetaRide Jul 6 '12 at 6:05
  • Did you find a satisfying solution now? – Turion Sep 14 '14 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.