function LinkCollectionNormalizer::hashByHref

Same name in other branches
  1. 9 core/modules/jsonapi/src/Normalizer/LinkCollectionNormalizer.php \Drupal\jsonapi\Normalizer\LinkCollectionNormalizer::hashByHref()
  2. 10 core/modules/jsonapi/src/Normalizer/LinkCollectionNormalizer.php \Drupal\jsonapi\Normalizer\LinkCollectionNormalizer::hashByHref()
  3. 11.x core/modules/jsonapi/src/Normalizer/LinkCollectionNormalizer.php \Drupal\jsonapi\Normalizer\LinkCollectionNormalizer::hashByHref()

Hashes a link by its href.

Parameters

\Drupal\jsonapi\JsonApiResource\Link $link: A link to be hashed.

Return value

string A 7 character alphanumeric hash.

1 call to LinkCollectionNormalizer::hashByHref()
LinkCollectionNormalizer::normalize in core/modules/jsonapi/src/Normalizer/LinkCollectionNormalizer.php

File

core/modules/jsonapi/src/Normalizer/LinkCollectionNormalizer.php, line 93

Class

LinkCollectionNormalizer
Normalizes a LinkCollection object.

Namespace

Drupal\jsonapi\Normalizer

Code

protected function hashByHref(Link $link) {
    if (!$this->hashSalt) {
        $this->hashSalt = Crypt::randomBytesBase64();
    }
    return substr(str_replace([
        '-',
        '_',
    ], '', Crypt::hashBase64($this->hashSalt . $link->getHref())), 0, 7);
}

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