Skip to content

Commit a71f7b0

Browse files
author
Jonas Holfeld
committed
kirby 4 compatibility
1 parent 77aa741 commit a71f7b0

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Kirby 3 Many To Many Field
22

3-
> ⚠️ Version 2.0 of this plugin uses the [Unique IDs](https://getkirby.com/docs/guide/uuids) (aka UUIDs) that are part of the Kirby core since Kirby 3.8.0. Make sure to only use it with Kirby 3.8.0 or higher (doesn't work with Kirby 4 though). Upgrading from 1.0 to 2.0 with existing content is not possible and will lead to corrupted data. ⚠️
3+
> Version 2.0.1 is compatible with Kirby 4!! To upgrade, just pull the latest version of this plugin before updating the Kirby core.
4+
5+
> ⚠️ Version 2.0 of this plugin uses the [Unique IDs](https://getkirby.com/docs/guide/uuids) (aka UUIDs) that are part of the Kirby core since Kirby 3.8.0. Make sure to only use it with Kirby 3.8.0 or higher (the latest version also works with Kirby 4). Upgrading from 1.0 to 2.0 with existing content is not possible and will lead to corrupted data. ⚠️
46
57
This plugin allows you to create many-to-many relationships between pages in Kirby. It is designed based on the many-to-many relationship commonly found in traditional database systems (hence the name). The relationship is bidirectional, meaning it can be edited from either side and is automatically updated on the other side. The relationship can have attributes that can be updated from both sides as well. You can define multiple many-to-many relations on one page. If a page with a relation to one or many other pages gets deleted, all relations to this page get deleted as well.
68

index.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
$relationFields = getRelationFields($newPage);
1818
foreach ($relationFields as $relation) {
1919
$relationField = $newPage->blueprint()->field($relation)['relatationField'];
20-
$oldRelationsArray = $oldPage->$relation()->toStructure()->toArray();
21-
$oldRelationsArray = array_map('unSetID', $oldRelationsArray);
22-
$newRelationsArray = $newPage->$relation()->toStructure()->toArray();
23-
$newRelationsArray = array_map('unSetID', $newRelationsArray);
20+
$oldRelationsArray = YAML::decode($oldPage->$relation()->value());
21+
$newRelationsArray = YAML::decode($newPage->$relation()->value());
2422
foreach($oldRelationsArray as $oldRelation) {
2523
if(!in_array($oldRelation, $newRelationsArray)) {
2624
try {
@@ -54,7 +52,7 @@
5452
// Checks if the relation field is present in the updated page
5553
foreach ($relationFields as $relation) {
5654
// Getting bosst-ids of related pages
57-
$foreignKeys = $page->$relation()->toStructure()->toArray();
55+
$foreignKeys = YAML::decode($page->$relation()->value());
5856
// Getting the boost-id value of the deleted page
5957
$primaryKey = $page->uuid();
6058
// Getting related page and relation field from the blueprint of the deleted page
@@ -66,8 +64,6 @@
6664
// Changing the relation-entry so it matches the entry at subpage
6765
$singleRelationAtForeign = $foreignKey;
6866
$singleRelationAtForeign['foreignkey'] = $primaryKey;
69-
// Deleting the id field set by the toArray() Method
70-
unset($singleRelationAtForeign['id']);
7167
// Deleting the relation entry from the related page
7268
deleteRelation($foreign_subPage, $singleRelationAtForeign, $relationField);
7369
}
@@ -91,7 +87,7 @@ function deleteRelation($page, $value, $relationField)
9187
{
9288

9389
// Getting relations field from page to delete from
94-
$fieldData = $page->$relationField()->toStructure()->toArray();
90+
$fieldData = YAML::decode($page->$relationField()->value());
9591
// Creating empty field
9692
$newFieldData = [];
9793
// Pushing all entries that dont match the deleted relation

0 commit comments

Comments
 (0)