Hi,
Every page has a field linkid
that I use as a shortcut for the actual URL in a custom link
kirbytag.
fields:
linkId:
label: LinkID
type: text
required: true
Therefore, I need every linkid
value to be unique.
I opted for using a page.update:before
hook where I first get all linkid
values to check if the current page’s value (which might not have been saved yet) is already present in the list of all link IDs.
However, I’m not sure how to get the the current page’s value.
This is the code I’ve written so far:
'hooks' => [
'page.update:before' => function(Kirby\Cms\Page $page, array $values, array $strings) {
// Verify that there are not duplicate link IDs.
$fieldName = option('sanofan.linkid-kirbytag.id-field-name');
function getFieldValue(Kirby\Cms\Page $page, string $fieldName) {
return $page->content()->fields()[$fieldName]->value;
}
$allLinkIds = [];
foreach(kirby()->site()->index() as $p) {
$id = getFieldValue($p, $fieldName);
$allLinkIds[] = $id;
}
$linkId = getFieldValue($page, $fieldName);
// ...
}
My questions:
- What values do the parameters
$values
and$strings
contain? If they contain the value that are not saved yet, how could I get the value of thelinkid
field? - Does
$allLinkIds
contain the link ID of the current page that was previously saved?
Cheers,
Stefan