For automatic link creation I recently created the AutoLinks module and reported about it.
After a short time of use, I noticed that I was missing something.
No problem with the ModuleStudio.
In the following article I'll show you how to further develop a module and its functions.
If you need a new field in your module, this requires an update routine for the module.
But one after the other.
As a further development I wanted the possibility to create a title for a link and to add a * to a link.
I extended the model in ModuleStudio by 2 fields; 'descriptionForLink' for a title(title="") of the link and a checkbox 'setAsterisk' for the option to add a *. Both fields are optional.
In order for the module to require an update after uploading to the server, I increased the version from 1.0.0 to 1.0.1.
To enable or disable the setting of the * for a link in the overview, I also activated the option Ajax toggle switch.
After generating the module, some minor adjustments were necessary.
On the one hand I have extended the FilterHookProvider a bit. The extended code asks if the option 'setAsterisk' is set or not and inserts the *.
You can also see the details on Github: https://github.com/Portugao/AutoLinks/blob/9dda0a255419c8b67b45b07068bad6a5368fd324/MU/AutoLinksModule/HookProvider/FilterHooksProvider.php#L58
As I write this, I notice that I didn't even use Zikula's ApiInterface to retrieve module variables; well, a good exercise and maybe I'll need it later anyway.
The variable '$variableApi' is defined before (see : https://github.com/Portugao/AutoLinks/blob/9dda0a255419c8b67b45b07068bad6a5368fd324/MU/AutoLinksModule/HookProvider/FilterHooksProvider.php#L32)
and then built into the constructor (see: https://github.com/Portugao/AutoLinks/blob/9dda0a255419c8b67b45b07068bad6a5368fd324/MU/AutoLinksModule/HookProvider/FilterHooksProvider.php#L38 ).
At the bottom the variable will be assigned with a setter function.
Then I have the use statement for the ApiInterface
and the service inserted in the hooks.yml.
As new fields have been added to the module, the database must be updated during the update.
Caused by the change of the version of the module a switch for the update is indicated with the reference 'New Version'.
when calling the Extension module.
For the update I overwrote the file 'AutoLinksModuleInstaller.php'.
And this in the function 'upgrade'.
The statement in the try block is sufficient for Zikula to see what has changed in the fields and update the database if necessary. See also: https://github.com/Portugao/AutoLinks/blob/9dda0a255419c8b67b45b07068bad6a5368fd324/MU/AutoLinksModule/AutoLinksModuleInstaller.php#L23
The code to update the database is provided in the base file 'AbstractAutoLinksModuleInstaller.php' commented out, i.e. generated by the module studio. All I needed to do was copy it and remove the comment.
If you now trigger the upgrade, the database will be updated and the module will be usable with version 1.0.1.
The extension of a module is fast with the ModuleStudio, because with version changes all relevant files of the module are updated. The function 'upgrade' works with the switch statement.
For a version change, not much effort is necessary, especially if no module variables are added.
Up to now AutoLinks does without own variables. Of course this can still change.
You should now have learned how to update when you change the version.