I’ve got a calendar on two places in the structure which should have the same content and structure (I know, don’t ask
The goal is: edit the calendar in one place and duplicate the data to the second place.
So I was playing around with hooks and everything seems to work except for sort($page->num()). When I sort pages the num for the specific page gets updated but the other items don’t update their num.
1-item-a
2-item-b
3-item-c
becomes
1-item-b
1-item-a
3-item-c
Anyone with a brilliant idea? (you may find this piece of code interesting
Check out kirby()->hook(‘panel.page.sort’, function($page) {
kirby()->hook('panel.page.create', function($page) {
if($page->template() == 'calendar.year') {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
$newPage = page(''.$targetdir.'')->children()->create(''.$page->slug().'', 'calendar.year', array(
'title' => ''.$page->title().''
));
return;
} catch(Exception $e) {
return $e->getMessage();
}
} elseif($page->template() == 'calendar.month') {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
$newPage = page(''.$targetdir.'')->children()->create(''.$page->slug().'', 'calendar.month', array(
'title' => ''.$page->title().''
));
return;
} catch(Exception $e) {
return $e->getMessage();
}
} elseif($page->template() == 'calendar.item') {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
$newPage = page(''.$targetdir.'')->children()->create(''.$page->slug().'', 'calendar.item', array(
'title' => ''.$page->title().''
));
return;
} catch(Exception $e) {
return $e->getMessage();
}
}
});
kirby()->hook('panel.page.update', function($page) {
if($page->template() == 'calendar.year') {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->update(array(
'title' => $page->title(),
'subtitle' => $page->subtitle(),
'link' => $page->link(),
'showpostscount' => $page->showpostscount(),
'class' => $page->class(),
'metakeywords' => $page->metakeywords(),
'metadescription' => $page->metadescription(),
));
return;
} catch(Exception $e) {
return $e->getMessage();
}
} elseif($page->template() == 'calendar.month') {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->update(array(
'title' => $page->title(),
'subtitle' => $page->subtitle(),
'link' => $page->link(),
'showpostscount' => $page->showpostscount(),
'class' => $page->class(),
'metakeywords' => $page->metakeywords(),
'metadescription' => $page->metadescription(),
));
return;
} catch(Exception $e) {
return $e->getMessage();
}
} elseif($page->template() == 'calendar.item') {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->update(array(
'title' => $page->title(),
'subtitle' => $page->subtitle(),
'pageup' => $page->pageup(),
'date' => $page->date(),
'introtext' => $page->introtext(),
'fulletext' => $page->fulltext(),
'calendar' => $page->calendar(),
'nextday' => $page->nextday(),
'thumbnail' => $page->thumbnail(),
'defaultimg' => $page->defaultimg(),
'class' => $page->class(),
'buttontext' => $page->buttontext(),
'buttonlink' => $page->buttonlink(),
'metakeywords' => $page->metakeywords(),
'metadescription' => $page->metadescription(),
));
return;
} catch(Exception $e) {
return $e->getMessage();
}
}
});
kirby()->hook('panel.page.delete', function($page) {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->delete($force = true);
return 'The page has been deleted';
} catch(Exception $e) {
return $e->getMessage();
}
});
kirby()->hook('panel.page.sort', function($page) {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->sort($page->num());
return 'The page is now visible and has the sorting number '.$page->num();
} catch(Exception $e) {
return $e->getMessage();
}
});
kirby()->hook('panel.page.hide', function($page) {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->hide();
return 'The page is now invisible';
} catch(Exception $e) {
return $e->getMessage();
}
});
kirby()->hook('panel.page.move', function($page) {
try {
$targetdir = str_replace('particulier','organisaties',$page->parent()->id());
page(''.$targetdir.'/'.$page->slug().'')->move();
return 'The page has been moved';
} catch(Exception $e) {
return $e->getMessage();
}
});