cer_profile2.cer.inc 1014 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Implements hook_cer_fields().
  4. */
  5. function cer_profile2_cer_fields() {
  6. $fields = array();
  7. // Create a fake field for each Profile2 type.
  8. foreach (array_keys(profile2_get_types()) as $profile_type) {
  9. // Profiles can only be attached to user accounts.
  10. $fields["user:user:profile_{$profile_type}"]['class'] = 'CerProfile2Field';
  11. }
  12. return $fields;
  13. }
  14. /**
  15. * Implements hook_cer_fields_alter().
  16. */
  17. function cer_profile2_cer_fields_alter(array &$fields) {
  18. foreach (array_keys($fields) as $identifier) {
  19. list ($entity_type, $bundle) = explode(':', $identifier);
  20. // If this field is instantiated on a Profile2, make CER treat it like a field
  21. // collection by first setting its parent field, and setting the 'require parent'
  22. // flag so that CER won't allow it to stand alone in a field chain.
  23. if ($entity_type == 'profile2') {
  24. $fields[$identifier]['parents'][] = "user:user:profile_{$bundle}";
  25. $fields[$identifier]['require parent'] = TRUE;
  26. }
  27. }
  28. }