Add Workflow to a Custom Permission Key

The first step toward enabling workflow on a custom permission key is making sure that you add the permission key with the workflow option enabled. Let\'s look at a previous custom permission key we added, in the install() method of a package controller:

$permission = Key::getByHandle('delete_product');
if (!is_object($permission)) {
    $view = Key::add('product', 'delete_product', 'Delete Product', '', false, false, $pkg);
}

In this code snippet, we're adding a permission key for deleting a product in our custom eCommerce package. See those two false statements? The first controls whether the key has workflow enabled (the second controls whether a custom permission key is used.) Simply set that first false to true to enable workflow on the permission.

$permission = Key::getByHandle('delete_product');
if (!is_object($permission)) {
    $view = Key::add('product', 'delete_product', 'Delete Product', '', true, false, $pkg);
}

That's it! By setting this to true, you've enabled the workflow tab in your custom permission, which you can then use to assign your centrally added workflows to the permission itself. This shows up when you edit the access entities attached to the "Delete Product" permission

Once you attach a workflow to this permission, you'll be ready to change the delete action itself to accommodate this workflow. Read on for more information on how to do that.