Skip to content

Commit

Permalink
Rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Nov 21, 2023
1 parent 6ed6360 commit 35f0976
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions config/methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 35f0976

Please sign in to comment.