PHP API: overrule restrictions from blueprint
Right now, there is no way to override any of the blueprint's options programatically, and that is severely limiting. Blueprint options are often used by the developer to control the interface presented to the user, rather than actually to restrict the functionality we want in our code. For example: I might have pages that I don't want the user to be able to delete, or change the template, or change the status, so I'll set those options to false in the blueprint - even though I might need to do those things to the page in my code.
A typical example is when using hooks to setup "subpage builders", as describe in this forum post. Because of our inability to override blueprint defaults, all subpages need to be created without restricting deletion, change of status, etc. - which in many cases would not be an acceptable solution.
Ideally, the methods that we already have to perform these functions on 'unlocked' blueprints could simply be extended with a $force flag, which could be used to override any blueprint checks. For instance:
// if $force == true then change even if changeStatus: false
$page->changeStatus('draft',,$force);
// if $force == true then change even if changeTemplate: false
$page->changeTemplate('newtemplate',$force);
// if $force == true then delete, even if delete: false
$page->delete($force);
That's actually a good idea.
@texnixe @distantnative
I went poking around in the code and found a solution that seems nice and simple. Adding:
if ($this->user->isKirby()) {
return true;
}
to ModelPermissions.php:55 allows the kirby superuser to bypass blueprint config. Then you can change the status/title/whatever like this:
$kirby->impersonate('kirby');
$page->changeStatus('listed');
$kirby->impersonate(null);
This seems to fit well with the way permissions are handled in other places, like creating a page.