Before diving into the developer guide, please make sure you have gone thru the Overview and User Guide sections.
Assuming you have done that, the developer guide will focus on the various methodologies for extending the SonicJs core including theming, module development, overriding core functions, advanced configuration, integration, etc.
Hooks are what gives SonicJs it's flexibility. It can be a bit confusing at first if you haven't worked with the event-emitter design pattern. However, once you get used to it, you'll see how well it enables us to follow the SOLID principals.
Hooks allow us to alter core functionality and even the functionality defined in other modules without touching the code within the target function.
Hooks are being added to the core and main modules continually. If you find a situation that you believe requires a new hook to be created in the core, please let us know!
Let's look at a simple example:
Simple enough right? We want a list of content types of a certain kind ("blog" in our example).
But what if we wanted to implement a site-wide rule dictating that we never wanted to display a blog post with a future publish date. This will allow us to load up our website with future blog post that will automatically publish once their publish date has been reached.
But there is a MUCH better way of adding this new business rule. Take a look at a different approach:
So we're doing the same thing as before, but we've broken away from the need to ever again have modify our core getDataForMyModule() function.
We can now very easily implement the "S" and "O" in SOLID - Each time we want to implement a business rule in our getDataForMyModule(), we can simply "subscribe" to the "emitter event" and inject our new code.
Modules allow you to extend and modify SonicJs' capabilities. Module file are isolated in their own folder yet can alter both core functionality and even functionality of other modules.
SonicJs modules are extremely powerful and flexible. Unlike most CMS, where modules offer only "bolt-on" style extension with perhaps some APIs to plug into, SonicJs allows the developer to completely alter the functions and/or data used throughout the system.
The easiest way to explore the awesomeness of SonicJs modules is to build and example. Let's do that!
We'll create a "Hello World" module in part 1 and then extend it in the subsequent parts. Let's get started!
That's it! We've created our first module and can now add it to a page.
Optional: Before we do that, open your project in your favorite IDE (ie VS Code) and check out the new files generated for you in the /server/modules/hello-world.
You should now see your module added to the page and it should be displaying the data that you entered in the First Name field.
Now, let's dig in a bit to our module and make some changes. Currently the output of our module looks like this: