Forums / Developer / Writing new modules

Writing new modules

Author Message

Tristan Koen

Thursday 12 June 2003 2:18:05 am

I have scoured the forums, contributed docs, etc but can't find any really useful documentation on writing new modules.

I have tried going through the source code to figure out what to do, but it is very obscure.

All I have managed to figure out so far is:
1. Create a directory for the new module under /kernel/.
2. Create a file named module.php that contains a set of associative arrays that do various things.
I can't find any docs that describe these arrays, their parameters and what they do though.
e.g. $ViewList has a whole bunch of elements including: 'functions', 'default_navigation_part', 'single_post_functions', 'post_action_parameters', 'post_actions', 'script' and 'params'. Where are these documented.
What role do the $ClassID, $ParentClassID, $SectionID, $Status, $Assigned, $Node, $Subtree and $FunctionList arrays play?
3. Add files for the various views of the module under the /kernel/mymodule/ directory. The output of each of these views is passed to the $Result associative array...
4. Admin interface can then be extended to accomodate the new function by supplying a set of new default and override templates.

I think I have the basics (please comment on any mistakes above), but it isn't enough to do anything useful at the moment.

Also, all of the existing code for the module views contains the following two lines:
$http =& eZHTTPTool::instance();
$Module =& $Params["Module"];

Why are they there? If I comment them out, the modules still work fine. I know what the first line does, but why is it there if the modujle doesn't need it? The second line is a complete mystery to me...

Perhaps I am missing something in the docs? I will be eternally grateful to anyone that can shed some light here.

Sven Ryen

Thursday 12 June 2003 6:48:53 am

Hi Tristan!

We're in the same boat, it seems... I just started looking into modules today.

The file:
    /lib/ezutils/classes/ezmodule.php
should provide you with info on how modules are executed.

Please post your findings here. I promise to do the same.

Sven Ryen

Thursday 12 June 2003 7:48:32 am

FWIW, I think the reccomended way of adding a module is to add an entry to either ModuleRepositories[] or ExtensionRepositories[] under [ModuleSettings] in module.ini.append.

Then, place your modules in the folder you add to ModuleRepositories[] or in a "modules/" subfolder inside the folder you add to ExtensionRepositories[].

So, if you need to add a module named "bar", you could add the file:
   /foo/modules/bar/module.php
and add "ExtensionRepositories[]=foo" to the file
   /settings/override/modules.ini.append

Sven Ryen

Thursday 12 June 2003 8:43:20 am

Note that some modules also have functions and operations, which are ? respectively ? defined in the files
    /kernel/<module_name>/function_definition.php
and
    /kernel/<module_name>/operation_definition.php

The functions and operations are executed by the files:
    /lib/ezutils/classes/ezmodulefunctioninfo.php
    /lib/ezutils/classes/ezmoduleoperationinfo.php

Sergiy Pushchin

Thursday 12 June 2003 11:19:56 am

1. You are right.
2. Yes you are right.
ViewList is set of views defined for module, for each view you define:
'functions' - to which functions user should have access to to be able to execute this view. so it used for permission system.
'default_navigation_part' - navigation part which should be active when this view is executed.
'single_post_functions' and 'post_action_parameters' is a mapping between post variables (buttons, input fields) and actions inside view.
'script' - php file which should be executed when user acceses this view.
'params' - params in url. for example url is 'content/edit/29658/1', content is modeule name, edit is view name and the last two numbers will be interpreted as parameters for the view.
"params" => array( "ObjectID", "EditVersion", 'EditLanguage' )
So inside a view you will be able to access
$Params["ObjectID"]; and $Params["EditVersion"]; they will get values 29658 and 1 by order. $Params["EditLanguage"]; will be empty since in url we have only two parts after view name separated with '/'
3.You are right.

about these two lines
$http =& eZHTTPTool::instance();
If you don't use it, it is not nessesary to put this line in view file

$Module =& $Params["Module"];
The same with this one. $Module object you get in this line gives you a lot of control on execution. For example you can use http redirections using its methods.

 

Sven Ryen

Thursday 12 June 2003 11:49:26 am

There's also documentation on module handling here:

http://www.ez.no/sdk/ezutils/view/module_handling/

Bruce Morrison

Thursday 12 June 2003 4:19:46 pm

Will someone from eZ please correct me if I'm wrong, but the proper way to add modules is via the extention system. This way you do not have to modify any ezpublish code only the configuration files. Upgrades a whole lot simpler if you use this method!

I looked at the ezRSS and glossary contributions as well as the online editor which all work this way and used these to create my own modules as extentions. These examples proved invaluable.

Cheers
Bruce
designIT

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Sven Ryen

Friday 13 June 2003 1:33:49 am

Ineed.

Extensions allows you to gather actions, datatypes, design, eventtypes, modules, settings and probably more in one convenient folder, improving portability and upgradability.