profile2.info.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Provides Entity metadata integration.
  5. */
  6. /**
  7. * Extend the defaults.
  8. */
  9. class Profile2MetadataController extends EntityDefaultMetadataController {
  10. public function entityPropertyInfo() {
  11. $info = parent::entityPropertyInfo();
  12. $properties = &$info[$this->type]['properties'];
  13. $properties['label'] = array(
  14. 'label' => t('Label'),
  15. 'description' => t('The profile label.'),
  16. 'setter callback' => 'entity_property_verbatim_set',
  17. 'setter permission' => 'administer profiles',
  18. 'schema field' => 'label',
  19. );
  20. $properties['type'] = array(
  21. 'type' => 'profile2_type',
  22. 'getter callback' => 'entity_property_getter_method',
  23. 'setter callback' => 'entity_property_verbatim_set',
  24. 'setter permission' => 'administer profiles',
  25. 'required' => TRUE,
  26. 'description' => t('The profile type.'),
  27. ) + $properties['type'];
  28. unset($properties['uid']);
  29. $properties['user'] = array(
  30. 'label' => t("User"),
  31. 'type' => 'user',
  32. 'description' => t("The owner of the profile."),
  33. 'getter callback' => 'entity_property_getter_method',
  34. 'setter callback' => 'entity_property_setter_method',
  35. 'setter permission' => 'administer profiles',
  36. 'required' => TRUE,
  37. 'schema field' => 'uid',
  38. );
  39. $properties['created'] = array(
  40. 'label' => t("Date created"),
  41. 'type' => 'date',
  42. 'description' => t("The date the profile was created."),
  43. 'setter callback' => 'entity_property_verbatim_set',
  44. 'setter permission' => 'administer profiles',
  45. 'schema field' => 'created',
  46. );
  47. $properties['changed'] = array(
  48. 'label' => t("Date changed"),
  49. 'type' => 'date',
  50. 'schema field' => 'changed',
  51. 'description' => t("The date the profile was most recently updated."),
  52. );
  53. return $info;
  54. }
  55. }
  56. /**
  57. * Implements hook_entity_property_info_alter().
  58. */
  59. function profile2_entity_property_info_alter(&$info) {
  60. // Add related profiles to the user object.
  61. $properties = &$info['user']['properties'];
  62. foreach (profile2_get_types() as $type_name => $type) {
  63. $properties['profile_' . $type_name] = array(
  64. 'type' => 'profile2',
  65. 'label' => t('@type_name profile', array('@type_name' => drupal_ucfirst($type->label))),
  66. 'description' => t("The users's @type_name profile.", array('@type_name' => $type->label)),
  67. 'getter callback' => 'profile2_user_get_properties',
  68. 'bundle' => $type_name,
  69. );
  70. }
  71. }