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