annotate core/modules/rest/rest.api.php @ 19:fa3358dc1485 tip

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