Skip to main content

For developers: events

Fileshelf can be extended with plugins of your own – exactly the way the Pro version does it. Fileshelf loads all plugins of the group fileshelf before it fires its events. The classes are in Graup\Component\Fileshelf\Administrator\Event.

The events are Fileshelf's public interface. Their names, arguments and public methods only change with a new major version.

The events

EventClassWhenWhat a plugin can do
onFileshelfResolveTokenResolveTokenEventThe request carries a token (t).grant() skips access level and password, reject() locks with reason token.
onFileshelfAccessAccessEventAfter status, token, access level and password; also in lists (context list).deny($reason, $message, $redirect) locks. In lists, never count or write.
onFileshelfBeforeSendBeforeSendEventAccess granted, before counting.setFile() swaps the file; Fileshelf checks it against the storage again.
onFileshelfAfterCountAfterCountEventAfter counting, before the first byte.Notification only; getRequestId() links it to the next event.
onFileshelfAfterSendAfterSendEventAfter sending, also when the visitor broke off.isCompleted(), getBytesSent(), getMethod().
onFileshelfDownloadDisplayDownloadDisplayEventDownload page, per position.addHtml() with finished, escaped HTML.
onFileshelfDashboardDashboardEventBackend dashboard.addTile($id, $title, $html, $order)order, $area) ($area: status, content, insight or setup); from 1.8.0 addAttention($id, $text, $link, $count, $label) for “Needs your attention”, only for a need for action with a way out; check your own right first.
onFileshelfAdminPagesAdminPagesEventDashboard and every plugin page.addPage($name, $title, $right, $icon) announces a page view=page&page=…; Fileshelf checks the right.
onFileshelfAdminPageAdminPageEventThe plugin page is shown.addHtml(), addAction($action, $label, $icon, $confirm).
onFileshelfAdminActionAdminActionEventAn action of the page runs; token, right and confirmation are checked.handled($message, $type).
onFileshelfFilesInUseFilesInUseEventTools, download form and media manager ask which files of the storage belong to plugins.claim($path) for your own files (e.g. older versions); they never count as unlinked.
onFileshelfSitePagesSitePagesEventMenu item “Extension page” and every call of such a page.addPage($name, $title, $login) announces a website page; with $login Fileshelf sends guests to the login.
onFileshelfSitePageSitePageEventThe page is shown.addHtml() with escaped HTML, setTitle(), getOptions() (menu item).
onFileshelfSiteActionSiteActionEventA form of the page was sent; token, page and login are checked.handled($message, $type, $redirect); Fileshelf escapes the message.
onFileshelfCategoryDisplayCategoryDisplayEventCategory page, positions beforeList and afterList.addHtml() with escaped HTML; getTotal() gives the number of listed downloads.
onFileshelfActionLogActionLogEventSince 1.3.0: Fileshelf or a plugin reports an action for the action log (password, approval, import).Message only: getAction(), getKind() (download, category, import), getItemId(), getTitle(), getDetails(). The plugin "Action Log - Fileshelf" writes it.
onFileshelfImportSourcesImportSourcesEvent (Pro)Since 1.3.0: the page "Import" collects its sources.addSource() with a class implementing SourceInterface of the import plugin (categories, downloads, table check).
onFileshelfResolveScopesResolveScopesEventFired by the Pro version (limits) as soon as a limit uses a scope type of another plugin; the Free version does not fire it.addScope($type, $id).

The download comes as a read-only DownloadRecord (without the password hash), never as a table object. Reasons of your own start with x-<plugin>-; the website then shows only the message.

Example

final class Example extends CMSPlugin implements SubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return ['onFileshelfAccess' => 'onAccess'];
    }

    public function onAccess(AccessEvent $event): void
    {
        if ($event->getContext() !== 'list' && !$this->allowed($event->getUser())) {
            $event->deny('x-example-hours', 'Downloads are possible on working days only.');
        }
    }
}

Plugins add form tabs to the download as with articles, with onContentPrepareForm (form com_fileshelf.download), and store them in onContentAfterSave (context com_fileshelf.download).

Pages on the website

With the menu item type Fileshelf → Extension page a plugin gets a page of its own on the website, without a component of its own. Forms of that page send task=extension.action, page, action and the form token to Route::_('index.php?option=com_fileshelf') – always build the address with Route::_(), a relative address is wrong under search engine friendly URLs. Plugins add tabs to the category form with onContentPrepareForm on the form com_categories.categorycom_fileshelf; Fileshelf loads the group fileshelf for it.

Deutsche Fassung