cer.api.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * In order to create relationships between reference fields, CER needs to know
  4. * about what reference fields are available, and how to handle them, which is
  5. * what this hook is for. It should always return an array, even if there are
  6. * no fields to expose. The ultimate goal of this hook is to define a flattened
  7. * hierarchy of all the reference-type fields that CER can use.
  8. *
  9. * A reference-type field is any type of field that can refer to an entity.
  10. * This is pretty broadly defined: for example, CER considers field collections
  11. * to be reference-type fields, since they refer to entities of the
  12. * field_collection_item type. Even though the field collection may be displayed
  13. * as an embedded part of its host entity, at heart it's still just a reference
  14. * to an entity.
  15. */
  16. function hook_cer_fields() {
  17. return array(
  18. // The keys should refer to a single field instance on a single bundle of a single
  19. // entity type, even for embedded entities like field collections (see below).
  20. 'node:article:field_related_pages' => array(
  21. // At the very least, each field you return here needs to have a 'class' set,
  22. // which is the class of the plugin which will handle this field. A CER field
  23. // plugin must be a sub-class of CerField, and there must be a separate plugin
  24. // for each *type* of field you want to integrate (CER provides support for
  25. // most reference-type fields out of the box, though). The class you provide
  26. // MUST be registered with the autoloader (i.e., you need to mention it in the
  27. // files[] array in your module's info file).
  28. 'class' => 'CerEntityReferenceField',
  29. ),
  30. // A field collection field is a type of reference field, so you can expose these
  31. // to CER too. If you want to refer to reference fields on field collections, you
  32. // must define the parent fields too, as in this example.
  33. 'node:page:field_my_field_collection' => array(
  34. 'class' => 'CerFieldCollectionField',
  35. ),
  36. 'field_collection_item:field_my_field_collection:field_related_articles' => array(
  37. 'class' => 'CerEntityReferenceField',
  38. // For fields that are embedded in other entities (the prime example being field
  39. // collections), the possible parents of the field need to be defined. The array
  40. // of parents should be an array of keys that are present in the aggregated result
  41. // of hook_cer_fields(). There could be many possible parents for a single field;
  42. // each parent represents another possible "route" to this field. If you leave
  43. // this out, CER will try to automatically detect the parents.
  44. 'parents' => array(
  45. 'node:page:field_my_field_collection',
  46. ),
  47. // Embedded fields might *require* a parent. At the time of this writing, this
  48. // really only applies to field collections. The "require parent" flag means that
  49. // this field MUST have at least one parent, or CER won't use it. You can probably
  50. // omit this key, and let CER detect the correct value.
  51. 'require parent' => TRUE,
  52. ),
  53. );
  54. }
  55. /**
  56. * Alter the information gathered by hook_cer_fields().
  57. */
  58. function hook_cer_fields_alter(array &$fields) {
  59. // Do clever things here.
  60. }