Tutorial 6: Control Post's Action Menu

Tutorial 6: Control Post's Action Menu

Action menu belongs to an item, Via API core app settings, we can add more action menu to each resource. Example, we can add edit and delete action menu to a post detail.

Step 1: Add action menu to the PostResource setting

In method PostResource::getMobileSettings() we add "action_menu" and define list of supported action. Each action has common configuration options

See the sample code:
PostResource.php
<?php
class PostResource extends ResourceBase
{
public function getMobileSettings($params = [])
{
$searchFilter = (new PostSearchForm());
$searchFilter->setLocal($this->getLocalization());
return self::createSettingForResource([
'resource_name' => $this->resource_name,
'search_input' => [
'placeholder' => 'Search Posts'
],
'sort_menu' => $searchFilter->getSortOptions(),
'filter_menu' => $searchFilter->getWhenOptions(),
'action_menu' => [
[
'label' => 'Edit',
'value' => Screen::ACTION_EDIT_ITEM,
'acl' => 'can_edit'
],
[
'label' => 'Delete',
'value' => Screen::ACTION_DELETE_ITEM,
'style' => 'danger',
'acl' => 'can_delete'
],
]
]);
}
}
 

Step 2: Add permission schema to resource response

Update FindOne API code and set extra permission. Ideally, permission schema is permission allowed or not of the current logged in user with the resource item
PostApi.php
<?php
/**