Introduction
Today, the HamZone community was featured by阮一峰老师. Issue 239 of the Weekly Newsletter In the middle, it quickly brought about a significant traffic surge, attracting people from all walks of life, including amateur radio enthusiasts and developers. I received a large number of friend requests, and after work, this article came to mind.
A person's energy reserves are simply too limited.
Since the community-based Flarum platform has been running for two months, I have experimented with developing several plugins through multiple iterations. These plugins aim to add features that reflect the amateur radio enthusiast's interests and highlight the platform's capabilities. Through this process, I have gained a good understanding of the plugin development mechanism and workflow within Flarum. Considering the limited availability of relevant documentation in China, I plan to create and publish documentation promptly so that more people can participate and develop even more interesting features. This article and the related series of documents will also be submitted to the FlarumCN community.
I primarily focus on backend Go development, with some limited experience in other areas. Moving forward, I will provide as much detail as possible in describing the processes. If you find any inaccuracies or omissions, please let me know.
First
Assume you have some familiarity with the PHP language and have experimented with tools like Composer and Laravel.
Assume you have a basic understanding of newer, emerging frontend development practices, including but not limited to the use of Vue, React, Node.js, and Webpack, and that plugin development will require knowledge of both frontend and backend technologies.
Assume you already have a basic understanding of operations and maintenance, such as the use of related packages like MySQL and Nginx.
Additionally, you will need to possess certain troubleshooting skills, relatively good coding habits, and the ability to effectively retrieve relevant documentation or knowledge.
If you lack the above prerequisites, the following tasks may present some challenges for you.
If you are interested in the PHP language, I highly recommend learning through php.net You can learn through the official website, or through video courses on platforms like Bilibili, and learning other skills is similar. This requires a certain amount of effort and time.
Next
Let's explore what Flarum is.
This is a very modern and popular community/forum framework, currently supported by a highly active open-source community. The official website describes it as:Modern, fast, and free!
He performed secondary development based on the PHP Laravel framework, and the interface uses a high-performance and lightweight JavaScript framework. Mithril。
It is released under the MIT license.
For more information about him, or a preview, please visit: Regarding Flarum Or, for more information, please visit the following links:
If you want to find out which people are using the Flarum framework to build communities, FlarumCN provides Community Exhibition The entrance area looks very good.
Recommended source code
I recommend a few representative plugins that may be helpful and provide useful references during your development process.
External plugins
During subsequent development, if you have any doubts about how a particular function should be implemented, you can usually find the answer in the Flarum community or the source code of open-source projects.
Internal plugins
Each Flarum site has its own unique community and features, and the HamZone community is no exception. I will also list some plugins within the community here to facilitate future development.
Specifically:
Secondary development: Modifying and adapting existing plugins that have already been developed.
Public: Public access to warehouse documents
Private: Consider internal security factors, do not open access. If needed, please contact me (preferably if you are an amateur radio enthusiast).
Let's go!
Flarum environment
It's essential to run the Flarum framework in your development environment.
In Installation | Flarum It provides a very detailed introduction, allowing you to get a general understanding first.
However, I would like to introduce another locally developed operating mode here.
For deploying environments like PHP, Composer, MySQL, Node.js, Webpack, etc., I won't elaborate further here.
Given engineering projects that involve both front-end and back-end environments, I strongly recommend using VSCode Develop coding tools and make some simple modifications:
- Git Bash terminal environment (Windows)
- VS Code extension: PHP Intelephense
Clone the Flarum source code files. Repository address:https://github.com/flarum/flarum
git clone git@github.com:flarum/flarum.git --depth=1
In the root directory of the engineering project, open the VS Code terminal and perform the following steps first:
composer install
Then
cd public/
Execute
php -S 127.0.0.1:8888

Access via browser:http://127.0.0.1:8888/
This allows you to see the "Install Flarum" message.

Once you have filled in the database configuration details, you will be able to obtain a basic development environment for your plugin.
Blank Extension Generator
Next, you need to create your own plugin development project within the Flarum environment. You can use the extension generator provided by the community to do this:
In this post, you can find more detailed discussions:Create a Flarum extension using the FriendsOfFlarum resources.
Refer to the development documentation for Flarum's plugin extensions, which provides a way to load modules during local development (English introduction), agreeing that all local Flarum extension packages should be placed in packages/ In the directory
To avoid disrupting the recently launched… php -S 127.0.0.1:8888 For services, we can use VS Code to open multiple terminals and run commands in a new terminal:
composer config repositories.0 path "packages/*"
If you want to learn more details, here's a good introduction that you can visit at: Flarum Second Development Project Configuration Guide Review the process, specifically regarding version control, and my personal suggestion is to... package/* Each folder within should be treated as a separate project for project management purposes.
Now, a plugin generator can be installed to facilitate subsequent development of multiple plugins.
npm install -g @friendsofflarum/create-flarum-extension
Within the directory created in the previous step, continue using the following command to generate blank content for filling:
create-flarum-extension [directory]
For example, you can execute the following command in the project's root directory:
create-flarum-extension packages/flarum-ext-hamzone-tools
Once successful, you will see the following screen, and he will guide you in creating your first plugin content.

If you are unsure about which options to choose, here is a preview:

Therefore, your engineering project folder might look like this:

Regarding the example in flarum-ext-hamzone-tools The contents of the plugin will be explained in the next chapter.
Enable plugin
In the previous step, a plugin template was successfully generated. At this point, it already had the basic files necessary for running, but some simple modifications were still needed to enable it within the Flarum admin interface.
Root directory of the project composer.json In the document, corresponding to require Field addition:
"requires": {
"hamzone/flarum-ext-hamzone-tools": "*@dev"
}
In the Flarum configuration file, modify as follows:
'debug' => True.
Run the terminal from the project root directory and execute:
composer require hamzone/flarum-ext-hamzone-tools@dev
Run the above steps on macOS.👆🏻Instructions may result in error messages:zsh: no matches were found, you can try to ~/.zshrc Add the following:
set no_nomatch

Within the backend control panel, the newly generated plugin then appeared:

However, when you clicked the switch to prepare to enable the plugin, an error message appeared:An error occurred when attempting to load this page.
Don't panic, we can go. storage/logs Within the folder, view the specific error information.
[2023-01-13 15:48:15] flarum.ERROR: InvalidArgumentException: File not found at path: flarum-ext-template\flarum\packages\flarum-ext-hamzone-tools/js/dist/admin.js......
It's clear that something is missing from the front-end requirements. dist File, simply go to packages/flarum-ext-hamzone-tools in js Execute each folder separately:
yarn install
build yarn
To re-access the backend interface, you can enable the plugin and obtain the default output.[hamzone/flarum-ext-hamzone-tools] Hello, administrator!

At this point, I have successfully deployed and run the first Flarum plugin in my local development environment.
In my research, I primarily referenced the following posts, and I would like to thank those who contributed:
If you have any further questions, please join the group for discussion:HamCQ Community Exchange Group
(This group is primarily aimed at amateur radio enthusiasts) && Developer)