Skip to content

Commit 0f930f1

Browse files
committed
docs: added more information about plugins
1 parent d29ec29 commit 0f930f1

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

docs/plugins.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ With phpMyFAQ 4.0 and later, we have a new, currently experimental plugin system
44
This system allows you to extend phpMyFAQ with new features.
55
The plugin system is based on the Symfony Dependency Injection component.
66

7-
## 9.1 Plugin installation
7+
## 9.1 Installation
88

99
Plugins are installed in the `content/plugins` directory of your phpMyFAQ installation.
1010
The plugin directory should contain a subdirectory for each plugin, e.g. `content/plugins/HelloWorld`.
1111
The plugin directory should contain a `HelloWorldPlugin.php` file that implements the `PluginInterface` interface.
1212
If you want to remove a plugin, you can delete the plugin in the plugin directory.
1313

14-
## 9.2 Plugin configuration
14+
## 9.2 Configuration
1515

1616
Plugins can have configuration options, implemented via the `PluginConfigurationInterface` interface.
1717
Configuration options can be defined in the plugin configuration class with Constructor Property Promotion by adding
18-
public properties.
18+
public properties. There are no other options to configure plugins at this time.
1919

2020
### 9.3.1 Example configuration class
2121

@@ -41,7 +41,7 @@ The plugin manager is an instance of the `PluginManager` class.
4141

4242
To uninstall a plugin, you can delete the plugin directory from the `content/plugins` directory.
4343

44-
## 9.5 Plugin examples
44+
## 9.5 Examples
4545

4646
phpMyFAQ comes with an example plugin that demonstrates how to use the plugin system called `HelloWorldPlugin`.
4747

@@ -50,9 +50,14 @@ phpMyFAQ comes with an example plugin that demonstrates how to use the plugin sy
5050
```php
5151
<?php
5252

53-
namespace App\Plugins\Plugin1;
53+
declare(strict_types=1);
5454

55-
use App\Core\PluginInterface;
55+
namespace phpMyFAQ\Plugin\MyPlugin;
56+
57+
use phpMyFAQ\Plugin\PluginEvent;
58+
use phpMyFAQ\Plugin\PluginInterface;
59+
use phpMyFAQ\Plugin\PluginConfigurationInterface;
60+
use phpMyFAQ\Translation;
5661
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5762

5863
class MyPlugin implements PluginInterface
@@ -84,6 +89,21 @@ class MyPlugin implements PluginInterface
8489
return null;
8590
}
8691

92+
public function getStylesheets(): array
93+
{
94+
return [];
95+
}
96+
97+
public function getTranslationsPath(): ?string
98+
{
99+
return null;
100+
}
101+
102+
public function getScripts(): array
103+
{
104+
return [];
105+
}
106+
87107
public function registerEvents(EventDispatcherInterface $dispatcher): void
88108
{
89109
$dispatcher->addListener('hello.world', [$this, 'onContentLoaded']);
@@ -120,7 +140,7 @@ class MyPlugin implements PluginInterface
120140
</div>
121141
```
122142

123-
## 9.6 Plugin stylesheets
143+
## 9.6 Stylesheets
124144

125145
Plugins can provide pre-compiled CSS files that will be automatically injected into both frontend and admin pages.
126146

@@ -155,7 +175,7 @@ public function getStylesheets(): array
155175
└── admin-style.css
156176
```
157177

158-
## 9.7 Plugin translations
178+
## 9.7 Translations
159179

160180
Plugins can provide translations in multiple languages that integrate seamlessly with phpMyFAQ's translation system.
161181

@@ -166,7 +186,7 @@ Plugins can provide translations in multiple languages that integrate seamlessly
166186
```php
167187
public function getTranslationsPath(): ?string
168188
{
169-
return 'translations'; // Path relative to plugin directory
189+
return 'translations'; // Path relative to the plugin directory
170190
}
171191
```
172192

@@ -231,7 +251,7 @@ plugin.{PluginName}.{messageKey}
231251
└── language_es.php
232252
```
233253

234-
## 9.8 Plugin JavaScript
254+
## 9.8 JavaScript
235255

236256
Plugins can provide pre-compiled JavaScript files that will be automatically injected into both frontend and admin pages.
237257

@@ -289,6 +309,7 @@ public function getScripts(): array
289309

290310
**Security notes:**
291311
- Always use strict mode (`'use strict'`)
312+
- Lint your code with ESLint, you can run `npx eslint phpmyfaq/content/plugins/YourPlugin//assets/` from the phpMyFAQ root
292313
- Wrap code in IIFE to avoid global namespace pollution
293314
- Validate and sanitize user input
294315
- Use DOM API safely

0 commit comments

Comments
 (0)