Modules extend the functionality of your homepage. With Zikula and the ModuleStudio(MOST) creating a module is easy and fast.
For some of my homepages I wanted to create the possibility to automatically convert certain terms into links.
So I planned the module Autolinks with the ModuleStudio, generated it and made it work for me with a little code of my own.
In the following I would like to show you how the model looks like in ModuleStudio and which own code I wrote.
The AutoLink entity has only 2 fields, namely 'supportedString' for the term to be converted into a link and 'neededLink' for the desired link.
Both fields are logically mandatory fields.
As you can see, I already made an entry for files that should be marked when re-generating the module with the ModuleStudio.
I have activated the Hook Provider filter in the integration settings. This is crucial for the functionality of the module. It makes it possible to search contents in text fields of other modules and to convert terms into links when hits are made.
The first field 'supportedStrings' is defined as the display pattern.
With these settings I generated the module and created it in Eclipse.
In order for the module to do what I want it to do, a little code was needed in the Filter Hook Provider.
In modules generated with the ModuleStudio the relevant Php files are located in the folder 'HookProvider'. The folder itself contains the file 'FilterHooksProvider.php'. The subfolder Base contains the base class 'AbstractFilterHooksProvider.php'.
Php and object-orientation allow the extension and overwriting of code.
The base class can be overwritten with the file in the main folder.
I extend the constructor to have the Entity Factory class available. I need this to get all AutoLink entries in the module from the database.
I changed the applyFilter function so that it searches for hits for each entry in the module and rewrites the content accordingly.
2 use statements make sure that I have the required classes, i.e. their properties and methods, available.
Zikula uses Symfony completely. This means that Zikula modules use the services from Symfony.
The functionality of the hook provider is one such service.
So that this service can use the Entity Factory class of AutoLinks, it must be made known. This is done in various YAML files located in the 'Resources/config' folder of AutoLinks.
In the file hooks.yml I add the Entity Factory class to the filter_hooks.provider service so that I can use it.
Backend in AutoLinks
An entry in the backend of Autolinks then looks like this.
All occurrences of '#Banane#' are changed to corresponding links in text fields of modules connected with AutoLinks in the frontend.
AutoLinks is a conceptually simple module, with a quite complex functionality.
The planning, generation with the ModuleStudio and the addition of the code cost me half an hour.
It can be installed and used directly. With the ModuleStudio and a little bit of programming experience, many things can be implemented quickly.
An official release is already available, version 1.0.1 will be released soon.
Project page of AutoLinks: https://github.com/Portugao/AutoLinks