Building modules for Zikula - Extending modules

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.


Add new fields - What to keep in mind?

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.

Model in ModuleStudio

Other articles in this series of articles


Building modules for Zikula - It's as simple as that
Modules extend the functionality of your homepage. With Zikula and the ModuleStudio(MOST) creating a... More

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.

Modell im ModuleStudio

To enable or disable the setting of the * for a link in the overview, I also activated the option Ajax toggle switch.

AutoLinks Ajax Umschalter

Adjustments after generation

After generating the module, some minor adjustments were necessary.

FilterHookProvider - Option setAsterisk check

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 *.

if necessary.

You can also see the details on Github: https://github.com/Portugao/AutoLinks/blob/9dda0a255419c8b67b45b07068bad6a5368fd324/MU/AutoLinksModule/HookProvider/FilterHooksProvider.php#L58

AutoLinks 2 FilterHook 1

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.

VariableApiInterface from Zikula

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

AutoLinks 2 FilterHook 2

and the service inserted in the hooks.yml.

AutoLinks 2 FilterHook 3

Update to version 1.0.1

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'.

AutoLinks 2 Installer Update

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.

Fulness

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.

Similar articles with corresponding issues


Categories

  • ModuleStudio
  • Module

Creation and update

Creation
Created by michael.ueberschaer on Oct 27, 2018, 9:09 PM
Last update
Updated by michael.ueberschaer on Oct 31, 2018, 4:37 PM
Categories in Blog The latest downloads
  • Zikula 1.5.9
    Read more
  • Zikula 2.0.12
    Read more
  • Bootstrap Standard Theme
    Für Zikula 2.0.11 oder höher - For Zikula 2.0.11 or higher. Dieses Theme ist als...
    Read more
  • Blogging 1.1.0
    Mehrsprachiges Bloggen - Multilingual blogging
    Read more
  • AutoLinks 1.0.1
    Automatische Linkerstellung - Automatic link creation
    Read more