Create a Plugin
Aquesta pàgina encara no està disponible en el teu idioma.
Missing a feature in Castopod? Build it as a plugin and even share it with the community!
In order to get started, you first need to set up your Castopod dev environment.
1. Create the plugin folder
Section titled “1. Create the plugin folder”You’ll first need to create your
plugin folder in the plugins/
directory.
Using the create command Recommended
Section titled “Using the create command ”To quickly get you started, you can have a folder generated for you using the following CLI command:
php spark plugins:create
👉 You will be prompted for metadata and hooks usage in order to have a personalized skeleton plugin generated for you!
Manual setup
Section titled “Manual setup”-
create a plugin folder inside a vendor directory
Directoriplugins
Directoriacme // vendor name
Directorihello-world/ // plugin name
- …
- …
-
add a manifest.json file
Directorihello-world
- manifest.json
See the manifest reference.
-
add the Plugin.php class
Directorihello-world
- manifest.json
- Plugin.php
2. Build your plugin
Section titled “2. Build your plugin”Now that your plugin folder is set, you can start working on your plugin’s logic by implementing the hooks needed.
Settings forms
Section titled “Settings forms”You can prompt users for data through settings forms.
These forms can be built declaratively using the
settings
attribute in your manifest.
{ "settings": { "general": { "field-key": { "type": "text", "label": "Enter a text" } }, "podcast": { "field-key": { "type": "text", "label": "Enter a text for this podcast" } }, "episode": { "field-key": { "type": "type", "label": "Enter a text for this episode" } } }}
This example will generate 3 different settings forms at 3 different levels in the Castopod admin area:
general
: a general formpodcast
: a form for each podcastepisode
: a form for each episode
You can then access the data (input by the user) via helper methods by specifying the field key as a parameter:
$this->getGeneralSetting('field-key');
$this->getPodcastSetting($podcast->id, 'field-key');
$this->getEpisodeSetting($episode->id, 'field-key');