function hook_hal_relation_uri_alter

Same name in other branches
  1. 8.9.x core/modules/hal/hal.api.php \hook_hal_relation_uri_alter()

Alter the HAL relation URI.

Modules may wish to alter the relation URI generated for a resource based on the context of the serializer/normalizer operation.

Parameters

string $uri: The URI to alter.

array $context: The context from the serializer/normalizer operation.

See also

\Symfony\Component\Serializer\SerializerInterface::serialize()

\Symfony\Component\Serializer\SerializerInterface::deserialize()

\Symfony\Component\Serializer\NormalizerInterface::normalize()

\Symfony\Component\Serializer\DenormalizerInterface::denormalize()

Related topics

1 function implements hook_hal_relation_uri_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

hal_test_hal_relation_uri_alter in core/modules/hal/tests/modules/hal_test/hal_test.module
Implements hook_hal_relation_uri_alter().
1 invocation of hook_hal_relation_uri_alter()
RelationLinkManager::getRelationUri in core/modules/hal/src/LinkManager/RelationLinkManager.php
Gets the URI that corresponds to a field.

File

core/modules/hal/hal.api.php, line 52

Code

function hook_hal_relation_uri_alter(&$uri, $context = []) {
    if ($context['mymodule'] == TRUE) {
        $base = \Drupal::config('hal.settings')->get('link_domain');
        $uri = str_replace($base, 'http://mymodule.domain', $uri);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.