| 2 comments ]

I would like to share some basics about plugin development in elgg .

In elgg all the plugins will be in mod directory. You can drop your plugin in this directory.

First you need a name for your plugin.The names of the plugins in an installation must be unique.


you need a ‘start.php’ file for each plugin which to describe the common functions for a plugin.This file can be considered as the core controller of all plugins .The start.php must have an init function which initializes the plugin .

You have to register this function to elgg system and have to make sure the initialisation function is called on initialisation.

The following is a sample if the init functuion is yourplugin_init()

register_elgg_event_handler('init','system',’yourplugin _init');


In common the elgg plugin will have following folders

actions : Commonly all action(normally form actions) files are saved in this folder.

And you can register all the actions involved in a plugin with in its start.php file

The function is as follows .

register_action($action, $public = false, $filename = "", $admin_only = false)

For example

register_action('blog/add',false,$CONFIG->pluginspath . "blog/actions/add.php");

the parameters of the register_action indicates

action : The name of the action (here "blog/add")

second parameter is a Boolean parameter.which indicates whether the action is public or not that is whether this action be accessed by people not logged into the system or not.In above example false indicates that it is not a public action.

Next is filename that is where the action is located here the action is located in blog/actions/add.php , $CONFIG->pluginspath gives the path to plugin s that is the full path to mod directory of your elgg installation .

And if it is required you can register the action as admin action .you have to set the fourth parameter as true for this by default it in false.


Views : In common all html files will be in this folder .You can call these views in the plugin using the function

elgg_view(‘viewname’,$array_of params)

You can override existing views also.The view lodes based on the plugin priority.

You can extend views using the function extend_view('original view ','your view');


The view folder contains a default folder which holds all the views of plugin .For the easiness .For the easiness you can use subfolders in the default folder.

For example if you have a plugin named blog and it have a view called create.php in the path views /defaults/blogs/create.php you can call this view like ‘blogs/create ‘ .That is you can call the view as follows elgg_view(‘blogs/create’)

Language file :

This file contains the language translations for the plugin.

Creating Friendly URLS:

You can create nice URLs for your plugin using page handler function.for doing this you have to define and register a page handler in `start.php`,


function handlerfunction($page) {

switch ($page[0])

{

case 'index':

Your code for the index view

break;

case 'your_view':

include(‘yourview’);

break;

}

}

register_page_handler(handler, 'handler_function’);

in this function the first argument handler is your entity type, the next argument is the your plugin function handling the request which will get passed as an array in `$page` this carries each url segments. You can check for a location and can create the cases corresponding to that.



User settings:

Plugins might have some settings , You can create the view in the file settings.phpand you can retrieve the settings by the following function

get_plugin_setting($name, $plugin_name );

and you can set values using

set_plugin_setting($name, $value, $plugin_name);function

You can create widgets on your plugins .The widget might be in the folder views/default/widgets

The widgets folder may have two files one is view.php that is view of widget and the other is eidt.php that is the page for setting the widget display options like number of items to be displayed etc.

You can initialize the widget in the init function using the following function

add_widget_type('widgettitle',$name_of_widget,$desc_of_widget) .

2 comments

Anonymous said... @ Tuesday, April 27, 2010 at 12:11:00 AM GMT+1

how to override an action from existing core classes?

Anonymous said... @ Thursday, December 22, 2011 at 8:40:00 PM GMT

You spelled "loads" incorrectly as "lodes"

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.