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);
61 * Alter the REST relation URI.
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.
66 * @see https://www.drupal.org/node/2830467
68 * Modules may wish to alter the relation URI generated for a resource based on
69 * the context of the serializer/normalizer operation.
73 * @param array $context
74 * The context from the serializer/normalizer operation.
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()
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);
89 * @} End of "addtogroup hooks".