Drupal investigation

rest.api.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @file
  4. * Describes hooks provided by the RESTful Web Services module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Alter the resource plugin definitions.
  12. *
  13. * @param array $definitions
  14. * The collection of resource definitions.
  15. */
  16. function hook_rest_resource_alter(&$definitions) {
  17. if (isset($definitions['entity:node'])) {
  18. // We want to handle REST requests regarding nodes with our own plugin
  19. // class.
  20. $definitions['entity:node']['class'] = 'Drupal\mymodule\Plugin\rest\resource\NodeResource';
  21. // Serialized nodes should be expanded to my specific node class.
  22. $definitions['entity:node']['serialization_class'] = 'Drupal\mymodule\Entity\MyNode';
  23. }
  24. // We don't want Views to show up in the array of plugins at all.
  25. unset($definitions['entity:view']);
  26. }
  27. /**
  28. * Alter the REST type URI.
  29. *
  30. * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
  31. * hook_serialization_type_uri_alter() instead. This exists solely for BC.
  32. *
  33. * Modules may wish to alter the type URI generated for a resource based on the
  34. * context of the serializer/normalizer operation.
  35. *
  36. * @param string $uri
  37. * The URI to alter.
  38. * @param array $context
  39. * The context from the serializer/normalizer operation.
  40. *
  41. * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
  42. * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
  43. * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
  44. * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
  45. */
  46. function hook_rest_type_uri_alter(&$uri, $context = []) {
  47. if ($context['mymodule'] == TRUE) {
  48. $base = \Drupal::config('serialization.settings')->get('link_domain');
  49. $uri = str_replace($base, 'http://mymodule.domain', $uri);
  50. }
  51. }
  52. /**
  53. * Alter the REST relation URI.
  54. *
  55. * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
  56. * hook_serialization_relation_uri_alter() instead. This exists solely for BC.
  57. *
  58. * Modules may wish to alter the relation URI generated for a resource based on
  59. * the context of the serializer/normalizer operation.
  60. *
  61. * @param string $uri
  62. * The URI to alter.
  63. * @param array $context
  64. * The context from the serializer/normalizer operation.
  65. *
  66. * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
  67. * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
  68. * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
  69. * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
  70. */
  71. function hook_rest_relation_uri_alter(&$uri, $context = []) {
  72. if ($context['mymodule'] == TRUE) {
  73. $base = \Drupal::config('serialization.settings')->get('link_domain');
  74. $uri = str_replace($base, 'http://mymodule.domain', $uri);
  75. }
  76. }
  77. /**
  78. * @} End of "addtogroup hooks".
  79. */