October CMS – Add Menu Item And Store Backend Settings

October CMS Logo

At some point you probably want to make your custom plugin for October CMS configurable and allow backend users to make changes within the plugin space. October CMS has a simple and intuitive backend navigation, which you can easily extend in no-time. Let’s assume you have a custom plugin that calls an external API. Here is how you can store API credentials by using the Settings Manager.

First of all, you must register the settings in your Plugin.php file.

After that you must create a Settings.php file with the following content inside your models folder.

If you define default values inside the method initSettingsData, make sure the above fields match with the definitions inside the fields.yaml file.

Once the fields.yaml file is created, you should see a new form within the new tab.october_cms_playground_sandbox_backend_system_item

Now you can access the settings values within your controller, console or component by implementing the following model.

For test purposes, I created a new controller and implemented the above model to get access to the API key.

Here you go.

october_cms_playground_sandbox_frontend_output

The entire source code can be found on https://github.com/tobias-forkel/october-cms-playground.

The requested component (“settings”) is not found. Before using, you must add the implementation.

I tried to implement a simple field validation for a checkbox Apply Special Price which I needed on the Catalog > Product > Edit page. Unfortunately my first attempt below didn’t work and broke the whole grid table.

Here is how I have defined the field apply_special_price in category_form.xml based on different stackoverflow posts.

As I said, it didn’t work at all. So, I kept researching and found a solution which allowed me to implement the validation rule without the nodes <settings> and <formElements> inside of <field>.

Basically, everything has to be defined inside of config otherwise the XML for your custom UI component will be invalid. The section validation allows you to define filters for pretty much every use case. The example below sets a field as mandatory and detects white spaces. Beside that it will make sure the value matches a specific regex pattern.

More validation options are available out-of-the-box.