Upgraded drupal core with security updates
[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  * @see https://www.drupal.org/node/2830467
38  *
39  * Modules may wish to alter the type URI generated for a resource based on the
40  * context of the serializer/normalizer operation.
41  *
42  * @param string $uri
43  *   The URI to alter.
44  * @param array $context
45  *   The context from the serializer/normalizer operation.
46  *
47  * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
48  * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
49  * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
50  * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
51  */
52 function hook_rest_type_uri_alter(&$uri, $context = []) {
53   if ($context['mymodule'] == TRUE) {
54     $base = \Drupal::config('serialization.settings')->get('link_domain');
55     $uri = str_replace($base, 'http://mymodule.domain', $uri);
56   }
57 }
58
59
60 /**
61  * Alter the REST relation URI.
62  *
63  * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
64  *   hook_serialization_relation_uri_alter() instead. This exists solely for BC.
65  *
66  * @see https://www.drupal.org/node/2830467
67  *
68  * Modules may wish to alter the relation URI generated for a resource based on
69  * the context of the serializer/normalizer operation.
70  *
71  * @param string $uri
72  *   The URI to alter.
73  * @param array $context
74  *   The context from the serializer/normalizer operation.
75  *
76  * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
77  * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
78  * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
79  * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
80  */
81 function hook_rest_relation_uri_alter(&$uri, $context = []) {
82   if ($context['mymodule'] == TRUE) {
83     $base = \Drupal::config('serialization.settings')->get('link_domain');
84     $uri = str_replace($base, 'http://mymodule.domain', $uri);
85   }
86 }
87
88 /**
89  * @} End of "addtogroup hooks".
90  */