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 * @see https://www.drupal.org/node/2830467
39 * Modules may wish to alter the type URI generated for a resource based on the
40 * context of the serializer/normalizer operation.
44 * @param array $context
45 * The context from the serializer/normalizer operation.
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()
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);
60 * Alter the REST relation URI.
62 * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
63 * hook_serialization_relation_uri_alter() instead. This exists solely for BC.
65 * @see https://www.drupal.org/node/2830467
67 * Modules may wish to alter the relation URI generated for a resource based on
68 * the context of the serializer/normalizer operation.
72 * @param array $context
73 * The context from the serializer/normalizer operation.
75 * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
76 * @see \Symfony\Component\Serializer\SerializerInterface::deserialize()
77 * @see \Symfony\Component\Serializer\NormalizerInterface::normalize()
78 * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize()
80 function hook_rest_relation_uri_alter(&$uri, $context = []) {
81 if ($context['mymodule'] == TRUE) {
82 $base = \Drupal::config('serialization.settings')->get('link_domain');
83 $uri = str_replace($base, 'http://mymodule.domain', $uri);
88 * @} End of "addtogroup hooks".