Skip to content

Commit

Permalink
Merge pull request #10 from pichiste/master
Browse files Browse the repository at this point in the history
Fixing bug with creating relations to draft pages
  • Loading branch information
jonasholfeld authored Jan 15, 2024
2 parents fe93674 + c61e358 commit e1a34ec
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if (relationIsChanged($newPage, $oldPage, $relation)) {

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

// Getting the autoid value of the updated page
Expand Down Expand Up @@ -99,7 +99,7 @@
$primaryKey = $page->AUTOID();

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

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

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

return true;
} catch (Exception $e) {
return $e->getMessage();
}
}
}
}

0 comments on commit e1a34ec

Please sign in to comment.