From 35f09768a767e9b967d002ffa5a250d571413d9d Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 21 Nov 2023 10:14:39 +0100 Subject: [PATCH] Rename method --- config/methods.php | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/config/methods.php b/config/methods.php index 6e6628bd64..fd68402bb3 100644 --- a/config/methods.php +++ b/config/methods.php @@ -250,38 +250,6 @@ return $field->isNotEmpty() ? new QrCode($field->value) : null; }, - /** - * Parses the field value as DOM and replaces - * any permalinks in href/src attributes with - * the regular url - */ - 'toResolvedUrls' => function (Field $field): Field { - if ($field->isNotEmpty() === true) { - $dom = new Dom($field->value); - $attributes = ['href', 'src']; - $elements = $dom->query('//*[' . implode(' | ', A::map($attributes, fn ($attribute) => '@' . $attribute)) . ']'); - - foreach ($elements as $element) { - foreach ($attributes as $attribute) { - if ($url = $element->getAttribute($attribute)) { - try { - if ($uuid = Uuid::for($url)) { - $url = $uuid->model()->url(); - $element->setAttribute($attribute, $url); - } - } catch (InvalidArgumentException) { - // ignore anything else than permalinks - } - } - } - } - - $field->value = $dom->toString(); - } - - return $field; - }, - /** * Converts a yaml field to a Structure object */ @@ -496,6 +464,38 @@ return $field; }, + /** + * Parses the field value as DOM and replaces + * any permalinks in href/src attributes with + * the regular url + */ + 'permalinksToUrls' => function (Field $field): Field { + if ($field->isNotEmpty() === true) { + $dom = new Dom($field->value); + $attributes = ['href', 'src']; + $elements = $dom->query('//*[' . implode(' | ', A::map($attributes, fn ($attribute) => '@' . $attribute)) . ']'); + + foreach ($elements as $element) { + foreach ($attributes as $attribute) { + if ($element->hasAttribute($attribute) && $url = $element->getAttribute($attribute)) { + try { + if ($uuid = Uuid::for($url)) { + $url = $uuid->model()?->url(); + $element->setAttribute($attribute, $url); + } + } catch (InvalidArgumentException) { + // ignore anything else than permalinks + } + } + } + } + + $field->value = $dom->toString(); + } + + return $field; + }, + /** * Uses the field value as Kirby query */