hal.api.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Describes hooks provided by the HAL module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Alter the HAL type URI.
  12. *
  13. * Modules may wish to alter the type URI generated for a resource based on the
  14. * context of the serializer/normalizer operation.
  15. *
  16. * @param string $uri
  17. * The URI to alter.
  18. * @param array $context
  19. * The context from the serializer/normalizer operation.
  20. *
  21. * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
  22. * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
  23. * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
  24. * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
  25. */
  26. function hook_hal_type_uri_alter(&$uri, $context = []) {
  27. if ($context['mymodule'] == TRUE) {
  28. $base = \Drupal::config('hal.settings')->get('link_domain');
  29. $uri = str_replace($base, 'http://mymodule.domain', $uri);
  30. }
  31. }
  32. /**
  33. * Alter the HAL relation URI.
  34. *
  35. * Modules may wish to alter the relation URI generated for a resource based on
  36. * the context of the serializer/normalizer operation.
  37. *
  38. * @param string $uri
  39. * The URI to alter.
  40. * @param array $context
  41. * The context from the serializer/normalizer operation.
  42. *
  43. * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
  44. * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
  45. * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
  46. * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
  47. */
  48. function hook_hal_relation_uri_alter(&$uri, $context = []) {
  49. if ($context['mymodule'] == TRUE) {
  50. $base = \Drupal::config('hal.settings')->get('link_domain');
  51. $uri = str_replace($base, 'http://mymodule.domain', $uri);
  52. }
  53. }
  54. /**
  55. * @} End of "addtogroup hooks".
  56. */