Skip to content

Commit

Permalink
fix: don’t throw an exception if a model for a UUID cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Mar 7, 2024
1 parent 99174b3 commit c11bc8c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/extensions/fieldMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
*/
'resolvePermalinks' => function (Field $field) {
$kirby = $field->parent()->kirby();
$urlParser = $kirby->option('permalinksResolver.urlParser', fn (string $url, App $kirby) => $url);
$urlParser = $kirby->option('permalinksResolver.urlParser');

if ($field->isNotEmpty()) {
$dom = new Dom($field->value);
Expand All @@ -146,12 +146,13 @@

foreach ($elements as $element) {
foreach ($attributes as $attribute) {
if ($element->hasAttribute($attribute) && $url = $element->getAttribute($attribute)) {
if ($element->hasAttribute($attribute) && $uuid = $element->getAttribute($attribute)) {
try {
if ($uuid = Uuid::for($url)) {
$url = $uuid->model()?->url();
$parsedUrl = $url ? $urlParser($url, $kirby) : null;
$element->setAttribute($attribute, $parsedUrl);
if ($url = Uuid::for($uuid)?->model()?->url()) {
if (is_callable($urlParser)) {
$url = $urlParser($url, $kirby);
}
$element->setAttribute($attribute, $url);
}
} catch (InvalidArgumentException) {
// Ignore anything else than permalinks
Expand Down

0 comments on commit c11bc8c

Please sign in to comment.