If you have caching enabled in Drupal, instead of getting URLs like so:


You get:


What function would I need to call to get back the value = "RANDOMNESS"? I ask, because I want to cache other things using the same method Drupal does internally.

Any ideas?

  • 1
    That has nothing to do with caching, it's access protection for image styles. What do you want to protect, against what? – Berdir May 15 '17 at 20:33

The itok is defined in ImageStyle@getPathToken entity when building the URL (ImageStyle@buildUrl):

   * {@inheritdoc}
  public function getPathToken($uri) {
    // Return the first 8 characters.
    return substr(Crypt::hmacBase64($this->id() . ':' . $this->addExtension($uri), $this->getPrivateKey() . $this->getHashSalt()), 0, 8);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.