Skip to main content
Topic: Enabling 1.1 Addons (Read 2556 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Enabling 1.1 Addons

I may be completely missing something, but am I right in thinking it's not yet possible to enable a 1.1 addon from the core features list? Seems the AJAX call will just get given an "okay" response without anything being done to call the integration functions of the addon for enabling hooks, etc.

https://github.com/elkarte/Elkarte/blob/development/sources/controllers/Xml.controller.php#L165

Is this just something that isn't yet done?

Re: Enabling 1.1 Addons

Reply #1

Unless it's buggy it should...
I have an example on my other machine, I'll post it tomorrow. :)

I have to admit I wrote the code a while ago and while doing several other things (and changing my mind few times for few problems), so I don't remember exactly what I left there, but IIRC each addon has to do at least part of the work itself (i.e. enable modules and add hooks).
Bugs creator.
Features destroyer.
Template killer.


Re: Enabling 1.1 Addons

Reply #3

I have this:
Code: [Select]
<?php

class Test_Integrate
{
public static function register()
{
// $hook, $function, $file
return array(
array(
'integrate_something',
'ElkArte\\Addon\\Test\\Controller\\Test_Controller',
)
);
}

public static function settingsRegister()
{
// $hook, $function, $file
return array(
);
}
}
in a file names Test.integrate.php in "an" addons directory (I have it in "my" addons directory that is under sources, while the current one is in the root, but it shouldn't make much difference... I hope! O:-)).
This creates an entry in the core features list and when clicked it toggles properly and enables the "feature". At least here... :-[

Does it make sense?
Bugs creator.
Features destroyer.
Template killer.

Re: Enabling 1.1 Addons

Reply #4

I get the entry in the list, but toggling seems to do nothing. I can't get it to set any of the hooks present.

 

Re: Enabling 1.1 Addons

Reply #5

Ohh... okay, sorry, I'm dumb. Never mind.
Yeah, I did change my mind at some point and forgot to update the example.

My original thought was to let the code handle "everything" (like setting up of hooks), though at some point I realized that the core features code was not really designed to work the way I wanted, so instead of overhauling that code (or at least make some important changes) I decided it was easier to just let the coder deal with the way they wanted to integrate into Elk (in other words DIY).

Though, I added a "shortcut":
Code: [Select]
Hooks->get()->enableIntegration('Test_Integrate');
and the specular disableIntegration.

Using this method you can tell ElkArte to load a class at run-time and "register" live the hooks without having to pass through the database.
So, a better example would be:
Code: [Select]
<?php

class Test_Integrate
{
public static function register()
{
// $hook, $function, $file
return array(
array(
'integrate_something',
'Test_Integrate::a_function_to_call',
)
);
}

public static function setting_callback($value)
{
if (empty($value))
Hooks::get()->disableIntegration('Test_Integrate');
else
Hooks::get()->enableIntegration('Test_Integrate');
}

public static function a_function_to_call()
{
// Do something
}
}

This should let Elk call Test_Integrate::register "live", that will register hooks on-the-fly.

I know, this can be somehow slower than using the database (you have some more function calls), though it's much easier for people not used to code, for example if we want to give someone a snippet of code, now we have to package it because otherwise hooks will not be inserted into the database and the code will not run, this way, instead, hooks can be added and modified without having to install-uninstall-reinstall, etc. Just replace the file and the code will work. :)
Of course, an addon can use the "normal" way to load hooks, that's just "yet another way".

I hoe something of what I wrote makes sense... :-[
 emanuele runs
Bugs creator.
Features destroyer.
Template killer.