rules_test.module 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @file
  4. * Rules test module.
  5. */
  6. /**
  7. * Implements hook_entity_property_info_alter() to add a property without
  8. * access.
  9. */
  10. function rules_test_entity_property_info_alter(&$info) {
  11. $properties =& $info['site']['properties'];
  12. $properties['no_access_user'] = array(
  13. 'label' => t("Logged in user"),
  14. 'description' => t("The currently logged in user."),
  15. 'getter callback' => 'entity_metadata_system_get_properties',
  16. 'access callback' => 'rules_test_no_access',
  17. 'type' => 'user',
  18. );
  19. $properties =& $info['node']['properties'];
  20. $properties['reference'] = array(
  21. 'label' => t("Referenced entity"),
  22. 'getter callback' => 'rules_test_get_referenced_entity',
  23. 'type' => 'entity',
  24. );
  25. $properties['ref_nodes'] = array(
  26. 'label' => t("Referenced nodes"),
  27. 'getter callback' => 'rules_test_get_referenced_node',
  28. 'type' => 'list<node>',
  29. );
  30. }
  31. /**
  32. * Getter callback to get the referenced-entity property.
  33. */
  34. function rules_test_get_referenced_entity($node) {
  35. // For testing purposes we just return the node itself as property value.
  36. return entity_metadata_wrapper('node', $node);
  37. }
  38. /**
  39. * Getter callback to get the referenced-node list-property.
  40. */
  41. function rules_test_get_referenced_node($node) {
  42. // For testing purposes we just return the node itself as property value.
  43. return array($node->nid);
  44. }
  45. /**
  46. * Access callback. Returns TRUE except when $op == 'edit'.
  47. */
  48. function rules_test_no_access($op) {
  49. return $op == 'edit' ? FALSE : TRUE;
  50. }