cer_profile2.module 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. define('CER_PROFILE2_PATTERN', '/^user:user:profile_/');
  3. /**
  4. * Returns if either side of a preset refers to a profile2.
  5. *
  6. * @param \CerPreset $preset
  7. * The preset to test.
  8. *
  9. * @return bool
  10. */
  11. function _cer_profile2_is_profile2_preset(CerPreset $preset) {
  12. return preg_match(CER_PROFILE2_PATTERN, $preset->wrapper->cer_left->value()) || preg_match(CER_PROFILE2_PATTERN, $preset->wrapper->cer_right->value());
  13. }
  14. /**
  15. * Implements hook_entity_property_info_alter().
  16. */
  17. function cer_profile2_entity_property_info_alter(array &$info) {
  18. $struct = &$info['profile2']['properties']['cer']['property info'];
  19. $struct['lineage']['getter callback'] = 'cer_profile2_get_profile2_lineage';
  20. $struct['depth']['getter callback'] = 'cer_profile2_get_profile2_depth';
  21. $struct['owner']['getter callback'] = 'cer_profile2_get_profile2_owner';
  22. }
  23. /**
  24. * Entity API getter callback. Returns the lineage of a Profile2 entity.
  25. *
  26. * @return string
  27. */
  28. function cer_profile2_get_profile2_lineage(array $data, array $options, $property, $data_type, array $info) {
  29. return 'user:user:profile_' . $data[1]->type . ':profile2:' . $data[1]->type . ':';
  30. }
  31. /**
  32. * Entity API getter callback. Returns the depth of a Profile2. This is always
  33. * 1, since the profile is embedded directly under the user account as far
  34. * as CER is concerned.
  35. *
  36. * @return integer
  37. */
  38. function cer_profile2_get_profile2_depth(array $data, array $options, $property, $data_type, array $info) {
  39. return 1;
  40. }
  41. /**
  42. * Entity API getter callback. Returns the user account which owns a Profile2.
  43. *
  44. * @return EntityDrupalWrapper.
  45. */
  46. function cer_profile2_get_profile2_owner(array $data, array $options, $property, $data_type, array $info) {
  47. return new EntityDrupalWrapper('user', $data[1]->user());
  48. }