District Core Developer DocsDistrict Core Developer Docs
Developers
Boilerplate
Modules
Bitbucket
Developers
Boilerplate
Modules
Bitbucket
  • Modules

    • ABN
    • ActivityLog
    • AnalyticsApi
    • ApiConnector
    • BlockApi
    • CategoryApi
    • CloneApi
    • CommentApi
    • ContentApi
    • Core
    • Documents
    • EmbedApi
    • Event
    • ExportApi
    • FeatureApi
    • FormApi
    • GTM
    • GalleryApi
    • HelpApi
    • Hotspot
    • IdeaSurvey
    • ImportApi
    • InteractionsApi
    • Intercom
    • MailApi
    • MapApi
    • MapSurvey
    • MediaApi
    • MenuApi
    • MetaTagApi
    • NlpApi
    • NotificationApi
    • Page
    • ParentableContent
    • PaymentApi
    • PermissionsApi
    • Postcode
    • ReCaptcha
    • Redirects
    • Renderer
    • ReportApi
    • RestrictionApi
    • RevisionApi
    • SearchApi
    • Settings
    • ShareableApi
    • Slack
    • SlugApi
    • SubscribableApi
    • Survey
    • Team
    • TenantApi
    • TestApi
    • ThemeApi
    • Timeline
    • TranslationApi
    • Update
    • Users
    • VisualisationApi
    • WorkflowApi
    • Wysiwyg

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.

  1. 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);
    }

  1. Define routes defined by the Modules\ShareableApi\Services\ShareableApiService::generateShareableActionUrls method.
  2. Now these routes defined above are automatically injected onto the shareable component, but the create route may be needed to be imported onto the model specific action urls and should be placed as needed.
  3. Now $model->append(['shareable_link_component_props']) should hold all the required props needed for the frontend component.
  4. <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"
/>
  1. See Content model/module for reference and full implementation.

Permissions

  1. 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

  1. Once permission defined, use the policy method createShareableLink and deleteShareableLink for 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.

Edit this page
Prev
Settings
Next
Slack