Rules for the change of status

If I want to change the status of a page, how can I check if this page is added as a highlight in a multi select.

I want to prevent a page from being changed as a draft if this page exists in the selection. So that the user is informed that the selection of the highlight must be changed before the status of the page can be changed.

return [
    'hooks' => [
        'page.changeStatus:before' => function (Kirby\Cms\Page $page, string $status, ?int $position = null) {
            // I could check here if the respective page exists in the highlight selection

            //But how do I pass the hint on to the panel so that an error message or similar appears?
        }
    ]
]

Or can it also be solved with the Blueprint?

my current idea

estateoffers.txt

Highlights: page://TrFkM1zcQXbFKOtt, page://MNuAhVaqJI5HriFi
return [
    'hooks' => [
        'page.changeStatus:before' => function (Kirby\Cms\Pages $pages, Kirby\Cms\Page $page, string $status, ?int $position = null) {
        if ($page->template() == 'estateoffer') {
            $highlights = $pages->children()->template('estateoffers')->first()->content()->highlights()->split();
            foreach($highlights as $highlight){
                if($page->uuid() == $highlight){
                    // what next?
                }
            }

        }
    }
    ]
]

Or can it also be solved with the Blueprint?

options:
  changeStatus: true // would it be possible to set this to false or true via a query?

Docs: Page blueprint | Kirby CMS

I’m missing some information. This highlights field, is it in multiple pages or just in a single page (estateoffers). It this page the parent of the pages you want to check?

Yes, that’s correct.

Something like this

<?php
return [
  'hooks' => [

    'page.changeStatus:before' => function (Kirby\Cms\Page $page, string $status, ?int $position = null) {
      $parent = $page->parent();
      if ($parent && $parent->intendedTemplate()->name() === 'estateoffers' && $parent->hightlights()->toPages(',')->has($page)) {
        throw new ErrorException('Remove page from highlights before you can change its status');
      }
    }
  ],
];
1 Like

Big Thanks