Skip to content

Commit c61e358

Browse files
authored
Fixing bug with creating relations to draft pages
Using kirby()->page() instead of page()
1 parent fe93674 commit c61e358

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

index.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
if (relationIsChanged($newPage, $oldPage, $relation)) {
2828

2929
// Getting Content type and page from the blueprint of the updated page
30-
$relatedPage = page($newPage->blueprint()->field($relation)['relatedPage']);
30+
$relatedPage = kirby()->page($newPage->blueprint()->field($relation)['relatedPage']);
3131
$relationField = $newPage->blueprint()->field($relation)['relatationField'];
3232

3333
// Getting the autoid value of the updated page
@@ -99,7 +99,7 @@
9999
$primaryKey = $page->AUTOID();
100100

101101
// Getting related page and relation field from the blueprint of the deleted page
102-
$relatedPage = page($page->blueprint()->field($relation)['relatedPage']);
102+
$relatedPage = kirby()->page($page->blueprint()->field($relation)['relatedPage']);
103103
$relationField = $page->blueprint()->field($relation)['relatationField'];
104104

105105
foreach ($foreignKeys as $foreignKey) {
@@ -195,9 +195,9 @@ function addRelation($page, $value, $relationField)
195195
{
196196
// Getting relations field from page to add to
197197
try {
198-
$fieldData = YAML::decode(page($page)->$relationField()->value());
198+
$fieldData = YAML::decode(kirby()->page($page)->$relationField()->value());
199199
} catch (Throwable $e) {
200-
throw new Exception('Many to Many Field Plugin: related page or relatation field is faulty or missing. '.$e->getMessage());
200+
throw new Exception('Many to Many Field Plugin: related page or relatation field is faulty or missing. ' .$e->getMessage());
201201
}
202202

203203
// Getting Length of relations field before insert
@@ -215,11 +215,11 @@ function addRelation($page, $value, $relationField)
215215
// If fieldLengthAfter is same as fieldLengthBefore, nothing was added so we skip updating to avoid cascading
216216
if ($fieldLengthBefore !== $fieldLengthAfter) {
217217
try {
218-
page($page)->update([$relationField => YAML::encode($fieldData)]);
218+
kirby()->page($page)->update([$relationField => YAML::encode($fieldData)]);
219219

220220
return true;
221221
} catch (Exception $e) {
222222
return $e->getMessage();
223223
}
224224
}
225-
}
225+
}

0 commit comments

Comments
 (0)