ShareableAPI module
Provides shareable link functionality where users can create shareable link from backend which can then be used to view an unpublished model.Also contains a frontend only shareable popup component DistrictSharePopup for sharing to social media platforms.
Usage
Any model that needs shareable link should extend the Modules\ShareableApi\Concerns\Contracts\IsShareableInterface interface and use the Modules\ShareableApi\Concerns\HasShareableLinks trait. The trait provides with various helper methods needed for shareable links.
getShareableLinkComponentActionUrls()trait method then should be overriden by model.
/**
* {@inheritDoc}
*/
public function getShareableLinkComponentActionUrls(): array
{
if (! $this->getKey()) {
return [];
}
return ShareableApiService::generateShareableActionUrls($this, [
Model::ROUTE_MODEL_KEY => $this->getKey(),
], Model::ROUTE_MODEL_KEY);
}
- Define routes defined by the
Modules\ShareableApi\Services\ShareableApiService::generateShareableActionUrlsmethod. - Now these routes defined above are automatically injected onto the shareable component, but the
createroute may be needed to be imported onto the model specific action urls and should be placed as needed. - Now
$model->append(['shareable_link_component_props'])should hold all the required props needed for the frontend component. <dashboard-shareable-link>component is globally registered, hence we can use this component straight away
<component
:is="model.shareable_link_component_props.component"
class="dashboard-preview-section__content"
v-if="model.shareable_link_component_props"
v-bind="model.shareable_link_component_props"
/>
- See
Contentmodel/module for reference and full implementation.
Permissions
- For permissions, use below actions inside permissions enum for the corresponding model.
/**
* {@inheritdoc}
*/
public const ACTIONS = [
ShareableLinkPermissionsActions::CREATE,
ShareableLinkPermissionsActions::DELETE
];
See: Modules\Page\Plugins\Permissions\Enums\PagePermissions
- Once permission defined, use the policy method
createShareableLinkanddeleteShareableLinkfor consistency, with appropriate permission checks, which can then be used in controller methods.
Permission checks on the frontend while previewing a model.
To authorize viewing of a certain model use Modules\ShareableApi\Concerns\HasSessionAuthorizedPolicyCheck trait in the model policy utilizing the canViewSharedModel method provided by the trait on viewPublic policy method, @see ContentPolicy.