5 * Describes hooks provided by the RESTful Web Services module.
14 * Alter the resource plugin definitions.
16 * @param array $definitions
17 * The collection of resource definitions.
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
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';
27 // We don't want Views to show up in the array of plugins at all.
28 unset($definitions['entity:view']);
32 * Alter the REST type URI.
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.
37 * Modules may wish to alter the type URI generated for a resource based on the
38 * context of the serializer/normalizer operation.
42 * @param array $context
43 * The context from the serializer/normalizer operation.
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()
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);
59 * Alter the REST relation URI.
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.
64 * Modules may wish to alter the relation URI generated for a resource based on
65 * the context of the serializer/normalizer operation.
69 * @param array $context
70 * The context from the serializer/normalizer operation.
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()
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);
85 * @} End of "addtogroup hooks".