cer.properties.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @file
  4. * Contains entity property callback functions for the 'cer' struct exposed
  5. * to Entity API.
  6. */
  7. /**
  8. * Unpacks the cer_left and cer_right values into a CerFieldChain object.
  9. */
  10. function cer_unpack_field_chain($data, array $options, $property, $entity_type, array $info) {
  11. return CerFieldChain::unpack($data);
  12. }
  13. /**
  14. * Creates a parent struct for the lineage, depth, owner, and original properties.
  15. * All that these other callbacks really need is the entity type and object, so
  16. * that's what this returns.
  17. */
  18. function cer_get_cer_struct($entity, array $options, $property, $entity_type, array $info) {
  19. return array( $entity_type, $entity );
  20. }
  21. /**
  22. * Gets the lineage of the entity as a string, in the format entity_type:bundle:%
  23. */
  24. function cer_get_entity_lineage(array $data, array $options, $property, $data_type, array $info) {
  25. list (, , $bundle) = entity_extract_IDs($data[0], $data[1]);
  26. return $data[0] . ":{$bundle}:";
  27. }
  28. /**
  29. * Gets the entity depth as an integer. cer_entity_property_info_alter() overrides this
  30. * callback for field collections, and for all other entity types it's 0 (top level).
  31. */
  32. function cer_get_entity_depth(array $data, array $options, $property, $data_type, array $info) {
  33. return 0;
  34. }
  35. /**
  36. * Gets the ultimate owner of the entity as an EntityDrupalWrapper. cer_entity_property_info_alter()
  37. * overrides this callback for field collections, and for all other entity types the entity
  38. * owns itself.
  39. */
  40. function cer_get_entity_owner(array $data, array $options, $property, $data_type, array $info) {
  41. return new EntityDrupalWrapper($data[0], $data[1]);
  42. }
  43. /**
  44. * Gets the original entity, before update. If no update has taken place, the current
  45. * entity is returned.
  46. */
  47. function cer_get_entity_original(array $data, array $options, $property, $data_type, array $info) {
  48. return new EntityDrupalWrapper($data[0], (isset($data[1]->original) ? $data[1]->original : $data[1]));
  49. }