-
Notifications
You must be signed in to change notification settings - Fork 294
Storybook plugins guide #1415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kaitlinnewson
merged 7 commits into
pkp:main
from
jardakotesovec:storybook-plugins-guide
Nov 28, 2025
Merged
Storybook plugins guide #1415
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3fa5e52
Move plugin-guide 3.4 under 3.4 subfolder
jardakotesovec 750f223
Copy plugin-guide en files from 3.4 for 3.5
jardakotesovec 63401e7
Bump the plugin-guide files to 3.5
jardakotesovec 6af7f71
Reference Editorial UI extending via Vue.js on multiple places to mak…
jardakotesovec 265fa33
Fix plugin-guide indexes and add 3.5 to versions.yml
jardakotesovec 946a2d0
Add link to storybook for ui-library section for 3.5 and dev
jardakotesovec e98c19f
Add link for 3.5 plugin-guide to the card, remove storybook link from…
jardakotesovec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Summary | ||
|
|
||
| * [Introduction](.) | ||
| * [Getting Started](./getting-started) | ||
| * [Plugin Categories](./categories) | ||
| * [Blocks](./categories#blocks) | ||
| * [Import/Export](./categories#import-export) | ||
| * [Reports](./categories#reports) | ||
| * [Themes](./categories#themes) | ||
| * [Generic](./categories#generic) | ||
| * [Other](./categories#other) | ||
| * [Translation](./translation) | ||
| * [Templates](./templates) | ||
| * [Plugin Settings](./settings) | ||
| * [Release a Plugin](./release) | ||
| * [Examples](./examples) | ||
| * [Plugin Template](https://github.com/pkp/pluginTemplate){:target="_blank"} | ||
| * [Add Styles and Scripts](./examples-styles-scripts) | ||
| * [Context and Site](./examples-context-site) | ||
| * [Get Data](./examples-get-data) | ||
| * [Get Data from the Template](./examples-get-data-template) | ||
| * [Add Custom Fields](./examples-custom-field) | ||
| * [Add Custom Page](./examples-custom-page) | ||
| * [Events and Listeners](./example-events) | ||
| * [Add Editorial Decision](./example-decision) | ||
| * [Mailgun](https://github.com/Vitaliy-1/mailgun/) | ||
| * [Extend a Map](./examples-extend-map) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,268 @@ | ||
| --- | ||
| title: Plugin Categories - Plugin Guide for OJS, OMP and OPS | ||
| book: dev-plugin-guide | ||
| version: 3.4 | ||
| --- | ||
|
|
||
| # Plugin Categories | ||
|
|
||
| A plugin's category determines when it is loaded and how it can modify the application. For example, a [block](#blocks) plugin can add a block of content to the sidebar in the reader-facing website. But it can't do anything else and won't be loaded on the backend. | ||
|
|
||
| Each plugin must extend one of the plugin category classes. In the [Getting Started](./getting-started) tutorial, the Tutorial Example plugin extended the `GenericPlugin` class. | ||
|
|
||
| ```php | ||
| namespace APP\plugins\generic\tutorialExample; | ||
|
|
||
| use PKP\plugins\GenericPlugin; | ||
|
|
||
| class TutorialExamplePlugin extends GenericPlugin | ||
| { | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| A block plugin will extend the `BlockPlugin` class. | ||
|
|
||
| ```php | ||
| namespace APP\plugins\blocks\tutorialBlock; | ||
|
|
||
| use PKP\plugins\BlockPlugin; | ||
|
|
||
| class TutorialBlockPlugin extends BlockPlugin | ||
| { | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| Each plugin category class provides methods that must be implemented. For example, a [report](#reports) plugin extends the `ReportPlugin` class and implements the `ReportPlugin::display()` method to deliver a CSV file with the report contents. | ||
|
|
||
| ```php | ||
| namespace APP\plugins\reports\tutorialExample; | ||
|
|
||
| use PKP\plugins\ReportPlugin; | ||
|
|
||
| class TutorialExamplePlugin extends ReportPlugin | ||
| { | ||
| public function display($args, $request) | ||
| { | ||
| header('content-type: text/comma-separated-values'); | ||
| header('content-disposition: attachment; filename=reviews.csv'); | ||
| $fp = fopen('php://output', 'wt'); | ||
| fputcsv($fp, [/* the review details in the report */]); | ||
| fclose($fp); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Blocks {#blocks} | ||
|
|
||
| Block plugins provide content that can be displayed in the sidebar on any page of the public-facing website. They require a template file. | ||
|
|
||
| ``` | ||
| ojs | ||
| │ | ||
| ├─┬ plugins | ||
| │ │ | ||
| │ └─┬ blocks | ||
| │ │ | ||
| │ └─┬ madeBy | ||
| │ │ | ||
| │ ├─┬ templates | ||
| │ │ └── block.tpl | ||
| │ ├── MadeByPlugin.php | ||
| │ └── version.xml | ||
| ``` | ||
|
|
||
| The template file should include all of the HTML for your block. | ||
|
|
||
| ```html | ||
| <div class="pkp_block block_madeBy"> | ||
| Made with ❤ by the Public Knowledge Project | ||
| </div> | ||
| ``` | ||
|
|
||
| Add a `getContents()` method to pass data to the template. | ||
|
|
||
| ```php | ||
| namespace APP\plugins\blocks\madeBy; | ||
|
|
||
| use PKP\plugins\BlockPlugin; | ||
|
|
||
| class MadeByPlugin extends BlockPlugin | ||
| { | ||
| public function getContents($templateMgr, $request = null) | ||
| { | ||
| $templateMgr->assign([ | ||
| 'madeByText' => 'Made with ❤ by the Public Knowledge Project', | ||
| ]); | ||
|
|
||
| return parent::getContents($templateMgr, $request); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```html | ||
| <div class="pkp_block block_madeBy"> | ||
| {$madeByText|escape} | ||
| </div> | ||
| ``` | ||
|
|
||
| Block plugins can use any HTML code. However, themes provided by PKP expect blocks to use the following markup. | ||
|
|
||
| ```html | ||
| <div class="pkp_block"> | ||
| <h2 class="title"> | ||
| <!-- Add the title of your block here --> | ||
| </h2> | ||
| <div class="content"> | ||
| <!-- Add the main content for your block here --> | ||
| </div> | ||
| </div> | ||
| ``` | ||
|
|
||
| ## Import/Export {#import-export} | ||
|
|
||
| > View an [example import/export plugin](https://github.com/pkp/exampleImportExport). | ||
| {:.notice} | ||
|
|
||
| Import/export plugins provide tools for getting data into and out of OJS, OMP, and OPS. They can be used when you are moving between our application and another platform to migrate users, submissions, back issues and more. | ||
|
|
||
|
|
||
| Each import/export plugin can be run on the command line. | ||
|
|
||
| ``` | ||
| $ php tools/importExport.php ExampleImportExportPlugin import filename.csv | ||
| ``` | ||
|
|
||
| Use the `{plugin_url ...}` smarty function in the template to submit a form to one of the import or export paths. | ||
|
|
||
| ``` | ||
| <form method="POST" action="{plugin_url path="exportAll"}"> | ||
| <button type="submit">Export All</button> | ||
| </form> | ||
| ``` | ||
|
|
||
| Check the `path` to detect when the form is submitted. | ||
|
|
||
| ```php | ||
| namespace APP\plugins\importexport\exampleImportExport; | ||
|
|
||
| use PKP\plugins\ImportExportPlugin; | ||
|
|
||
| class ExampleImportExportPlugin extends ImportExportPlugin | ||
| { | ||
| // ... | ||
|
|
||
| public function display($args, $request) | ||
| { | ||
| parent::display($args, $request); | ||
|
|
||
| $path = array_shift($args); | ||
|
|
||
| if ($path === 'exportAll') { | ||
| // do something | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Reports {#reports} | ||
|
|
||
| > Reports can return any file format, but they usually generate a CSV file for use in spreadsheet software. | ||
| {:.notice} | ||
|
|
||
| Report plugins provide a simple interface for generating a file download. Reports may be generated for article usage statistics, reviewers or anything you want. | ||
|
|
||
| Report plugins extend the `ReportPlugin` class and implement the `display()` method. | ||
|
|
||
| ```php | ||
| namespace APP\plugins\reports\exampleReport; | ||
|
|
||
| use APP\submission\Submission; | ||
| use PKP\plugins\ReportPlugin; | ||
|
|
||
| class ExampleReportPlugin extends ReportPlugin | ||
| { | ||
| public function display($args, $request) { | ||
|
|
||
| // Get the first 100 submissions | ||
| $submissions = Repo::submission() | ||
| ->getCollector() | ||
| ->filterByContextIds([$context->getId()]) | ||
| ->limit(100) | ||
| ->getMany(); | ||
|
|
||
| // Stream to a CSV file | ||
| header('content-type: text/comma-separated-values'); | ||
| header('content-disposition: attachment; filename=articles-' . date('Ymd') . '.csv'); | ||
| $fp = fopen('php://output', 'wt'); | ||
| fputcsv($fp, ['ID', 'Title']); | ||
| /** @var Submission $submission */ | ||
| foreach ($submissions as $submission) { | ||
| fputcsv($fp, [ | ||
| $submission->getId(), | ||
| $submission->getCurrentPublication()->getLocalizedTitle() | ||
| ]); | ||
| } | ||
| fclose($fp); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Themes {#themes} | ||
|
|
||
| Themes control the design and layout of a journal, press or preprint server. Read the [Theming Guide](/pkp-theming-guide/en) to learn how to build your own themes. | ||
|
|
||
| ## Generic {#generic} | ||
|
|
||
| Generic plugins are loaded with every request. They hook into the application early in the [Request Lifecycle](/dev/documentation/en/architecture-request) and can be used to modify almost everything. | ||
|
|
||
| Generic plugins use [Hooks](/dev/documentation/en/utilities-hooks) to intervene in the application. Hooks should be added in a plugin's `register()` method. | ||
|
|
||
| > Always check if the plugin is enabled before adding a hook. Otherwise, your plugin will run even when it has been disabled. | ||
| {:.warning} | ||
|
|
||
| ```php | ||
| namespace APP\plugins\generic\tutorialExample; | ||
|
|
||
| use PKP\plugins\GenericPlugin; | ||
| use PKP\plugins\Hook; | ||
|
|
||
| class TutorialExamplePlugin extends GenericPlugin | ||
| { | ||
| public function register($category, $path, $mainContextId = null) | ||
| { | ||
| $success = parent::register($category, $path); | ||
|
|
||
| if ($success && $this->getEnabled()) { | ||
| Hook::add('Example::hookName', [$this, 'doSomething']); | ||
| } | ||
|
|
||
| return $success; | ||
| } | ||
|
|
||
| public function doSomething(string $hookName, array $args): ?bool | ||
| { | ||
| // Do something... | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Generic plugins are very powerful and can use any hook in the application. Look at the [examples](./examples) for ideas and learn about the most [common hooks](/dev/documentation/en/utilities-hooks#common-hooks). | ||
|
|
||
| ## Other {#other} | ||
|
|
||
| Other plugin categories are not often used. The best way to learn about them is to read the source code of one of the existing plugins. These categories include: | ||
|
|
||
| - `auth` plugins allow you to authorize and synchronize user accounts with a third-party source. | ||
| - `gateways` plugins allow you to add a new URL and respond to requests to that URL. | ||
| - `metadata` plugins implement a description of a metadata format. | ||
| - `oaiMetadataFormats` plugins add a metadata format to the application's OAI endpoint. | ||
| - `paymethod` plugins allow you to implement your own payment handling when using subscription and article fees. | ||
| - `pubIds` plugins allow you to add support for publication identifiers like URNs. | ||
|
|
||
| --- | ||
|
|
||
| Learn how to [translate your plugin](./translation) so that it can be used by many journals. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.