Module development question

Is there a method to inject the standard destination select boxes into a pre-existing page? I want to hook into the extension page so of course I can’t use the [font=Courier]drawselects()[/font] function that I could on a standalone page. Thanks!

Not to mention it’s been gradually written over the past 8 or 9 years, starting when PHP was a much less mature language. I definitely understand!

I need to look into this. Yes it’s possible. The problem with certain parts of any open source project is that there are sections that have been written by several different people with different thought processes in mind. So things work differently around.

We need a method to temporarily disable an extension and redirect any calls it makes to another destination, among other things.

Is it not possible to add these boxes to the extension page? The alternative is using a separate page that lists all the extensions with a destination box for each, but it makes more sense to have it all together. It’s a shame the hook method isn’t available for this one page, it’s so much more elegant (compared to other aspects of the code!)

Hmm, never mind I’ve answered my own question. Some digging around in the source code led me to the ModuleHook class, which led me to a wiki page: http://www.freepbx.org/trac/wiki/ModuleHooks

Looks like I can stop using [font=Courier]$currentcomponent->addguielem()[/font] at last!

I’d suggest having a “Hello World” module as part of the new wiki.

Hi Miken32. Thanks for your advice.

If you need more help you can find us in #freepbx-dev on irc on freenode. Or post here. Either way.

Have you looked at this: http://wiki.freepbx.org/display/DC/Module+Development If you have content suggestions for this page, tm1000 should be able to assist.

Ok so I have a module with this function but I can’t seem to inject anything into the extensions page:

<?php function modulename_hook_core($extdisplay, $pagename) { $html = "

Hello, world

"; return $html; } ?>

It seems to work on other core pages (trunks, inbound routes, etc.) but even there it just dumps it at the top of the page. I was expecting it would automagically create a section header and insert it somewhere reasonable in the page, similar to what the old functions did. Is there a way to do this?

PS it would be a lot more readable if <pre> and <code> blocks in the forums could be styled differently – monospaced and less padding.

I assume you substituted the defined rawname for the module you are working on in place of the word ‘modulename’ in the function definition.

Yup, as I said it injects the HTML on other pages, just not the extensions page.

So as Lorne (below me) knows some modules don’t support _hook_core. The core module (where extensions is contained is one of those that doesnt)

You’re going to want to do something like this in your functions.inc.php

function _applyhooks() { global $currentcomponent;
// Add the 'process' function - this gets called when the page is loaded, to hook into
// displaying stuff on the page.
$currentcomponent->addguifunc('<rawmodulename>_configpageload');

}

function _configpageload() {
}

See here (https://github.com/tm1000/freepbx-endpointmanager/blob/master/functions.inc.php) for more information on that. I can be more detailed if you need me to also.

Ok, that’s the method I’m familiar with already, but how can I use [font=Courier]drawselects()[/font] to create the select boxes if I’m stuck with [font=Courier]$currentcomponent->addguielem()[/font] to add stuff to the page?

Is there a reason you want to use drawselects? You know that it’s only for defining a destination right? and there is already a destination on the extensions page.

Gotcha. The reason is that the other pages include this line:

echo $module_hook->hookHtml

but the extensions page does not. There are quite a few pages that don’t allow html hooks and I’m not sure if that is a decision by the FreePBX devs or it is just the case that some modules just haven’t been brought up to date.

Looks like there a [font=Courier]gui_drawselects[/font] class which will do this. A little broken though, I’ve filed bug 6541.

Try to see if this helps out at all: https://github.com/POSSA/FreePBX-HelloWorld/blob/master/functions.inc.php