Skip to content

Commit 49f9851

Browse files
authored
fix: Storage for the page is immutable when saving page with kirby-seo fields
Trying the fix the `Storage for the page is immutable` error message that’s popping when using the plugin with Kirby 5.x. This basically only implements what Nico suggested in the Discord chat. Currently i can’t reproduce the issue reliably so i don’t know if this will fix it. Maybe someone can give it a try or let me know how to reproduce? Signed-off-by: Ove Numrich <[email protected]>
1 parent 3c43837 commit 49f9851

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

config/hooks.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
<?php
22

33
use Kirby\Cms\Page;
4+
use Kirby\Toolkit\A;
45
use Kirby\Toolkit\Str;
56

67
return [
78
'page.update:after' => function (Page $newPage, Page $oldPage) {
8-
foreach ($newPage->kirby()->option('tobimori.seo.robots.types') as $robots) {
9-
$upper = Str::ucfirst($robots);
10-
if ($newPage->content()->get("robots{$upper}")->value() === "") {
11-
$newPage = $newPage->update([
12-
"robots{$upper}" => 'default'
13-
]);
14-
}
15-
}
9+
$updates = A::reduce(
10+
$newPage->kirby()->option('tobimori.seo.robots.types'),
11+
function ($carry, $robots) use ($newPage) {
12+
$upper = Str::ucfirst($robots);
13+
14+
if ($newPage->content()->get("robots{$upper}")->value() === '') {
15+
$carry["robots{$upper}"] = 'default';
16+
}
17+
18+
return $carry;
19+
},
20+
[]
21+
);
22+
23+
$newPage = $newPage->update($updates);
24+
25+
return $newPage;
1626
},
1727
'page.render:before' => function (string $contentType, array $data, Page $page) {
1828
if (!class_exists('Spatie\SchemaOrg\Schema')) {

0 commit comments

Comments
 (0)