Created
June 3, 2021 16:47
-
-
Save nelson-ph/27128b4f034dd2b2f60f7b34d669fb22 to your computer and use it in GitHub Desktop.
Drupal 8 - Token image style url - support relative case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: token.tokens.inc | |
| IDEA additional info: | |
| Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
| <+>UTF-8 | |
| =================================================================== | |
| diff --git a/token.tokens.inc b/token.tokens.inc | |
| --- a/token.tokens.inc (date 1622738647667) | |
| +++ b/token.tokens.inc (date 1622738647667) | |
| @@ -1767,7 +1767,15 @@ | |
| $replacements[$original] = $style->buildUri($original_uri); | |
| } | |
| elseif ($property_name === 'url') { | |
| - $replacements[$original] = $style->buildUrl($original_uri); | |
| + if (count($parts) > 1) { | |
| + $filtered_tokens = [implode(':', array_slice($parts, 1)) => $filtered_tokens[implode(':', $parts)]]; | |
| + $url = Url::fromUri('base:'. file_url_transform_relative($style->buildUrl($original_uri))); | |
| + $field_tokens = \Drupal::token()->findWithPrefix($filtered_tokens, $property_name); | |
| + $replacements += \Drupal::token()->generate('url', $field_tokens, ['url' => $url], $options, $bubbleable_metadata); | |
| + } | |
| + else { | |
| + $replacements[$original] = $style->buildUrl($original_uri); | |
| + } | |
| } | |
| else { | |
| // Generate the image derivative, if it doesn't already exist. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment