synonyms_provider_field.api.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Documentation for Synonyms Provider Field module.
  5. */
  6. /**
  7. * Collect info about available field-based synonym behavior implementations.
  8. *
  9. * Hook to collect info about what PHP classes implement provided synonyms
  10. * behavior for different field types. If you to create synonyms behavior
  11. * implementation backed by some field type, this hook is for you. Information
  12. * from this hook will be post-processed based on existing fields and instances
  13. * and then inserted into hook_synonyms_behavior_implementation_info().
  14. *
  15. * @param string $behavior
  16. * Name of a synonyms behavior. This string will always be among the keys
  17. * of the return of synonyms_behaviors(), i.e. name of a cTools plugin
  18. *
  19. * @return array
  20. * Array of information about what synonyms behavior implementations your
  21. * module supplies. The return array must contain field types as keys, whereas
  22. * corresponding values should be names of PHP classes that implement the
  23. * provided behavior for that field type. Read more about how to implement a
  24. * specific behavior in the advanced help of this module. In a few words: you
  25. * will have to implement an interface that is defined in the behavior
  26. * definition. Do not forget to make sure your PHP class is visible to Drupal
  27. * auto discovery mechanism
  28. */
  29. function hook_synonyms_field_behavior_implementation_info($behavior) {
  30. switch ($behavior) {
  31. case 'autocomplete':
  32. return array(
  33. 'my-field-type' => 'MyFieldTypeAutocompleteSynonymsBehavior',
  34. );
  35. break;
  36. case 'another-behavior':
  37. return array(
  38. 'my-field-type-or-yet-another-field-type' => 'MyFieldTypeAnotherBehaviorSynonymsBehavior',
  39. );
  40. break;
  41. }
  42. return array();
  43. }
  44. /**
  45. * Alter info about available field-based synonyms behavior implementations.
  46. *
  47. * This hook is invoked right after
  48. * hook_synonyms_field_behavior_implementation_info() and is designed to let
  49. * modules overwrite implementation info from some other modules. For example,
  50. * if module A provides implementation for some field type, but your module has
  51. * a better version of that implementation, you would need to implement this
  52. * hook and to overwrite the implementation info.
  53. *
  54. * @param array $field_providers
  55. * Array of information about existing field-based synonyms behavior
  56. * implementations that was collected from modules
  57. * @param string $behavior
  58. * Name of the behavior for which the field-based synonyms behavior
  59. * implementations are being generated
  60. */
  61. function hook_synonyms_provider_field_behavior_implementation_info_alter(&$field_providers, $behavior) {
  62. switch ($behavior) {
  63. case 'the-behavior-i-want':
  64. $field_providers['the-field-type-i-want'] = 'MyFieldTypeAutocompleteSynonymsBehavior';
  65. break;
  66. }
  67. }