Skip to main content
Topic: Using the addon directory/autoloader (Read 4233 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Using the addon directory/autoloader

I'm working on an addon for a new site where we are going to start with 1.1 so I'm trying to use some of the new addon features that I've read about for 1.1.  That said I haven't been able to get my .integrate.php file to work.  It shows up in the Core Features, it lets me enable and disable it, but none of the hooks in the register method get loaded.  As far as I can tell the class never ends up in the autoload_integrate setting, which I assume it's supposed to from what I've been able to track in the code.  Any help would be much appreciated.

Code: [Select]
class Characters_Integrate
{
public static function setting_callback($value)
{
if ($value)
{
Hooks::get()->enableIntegration('Characters_Integrate');
}
else
{
Hooks::get()->disableIntegration('Characters_Integrate');
}
}


public static function register()
{
// $hook, $function, $file
return array(
array('integrate_action_post_before', 'Characters_Integrate::characterBeforePost'),
array('integrate_profile_areas', 'Characters_Integrate::loadCharacterProfileMenu'),
array('integrate_add_member_data', 'Characters_Integrate::addCharacterData'),
array('integrate_user_info', 'Characters_Integrate::loadCharacterSettings'),
array('integrate_member_context', 'Characters_Integrate::loadCharacterContext'),
);
}

public static function settingsRegister()
{
// $hook, $function, $file
return array();
}

Re: Using the addon directory/autoloader

Reply #1

Where did you put the file itself?
Bugs creator.
Features destroyer.
Template killer.

Re: Using the addon directory/autoloader

Reply #2

addons/Characters

Re: Using the addon directory/autoloader

Reply #3

 emanuele is tempted to call it a bug
Unfortunately, I changed my mind too many times...
Try editing Autoloader.class.php changing:
Code: [Select]
				$this->_file_name = SUBSDIR . '/' . $this->_givenname . '.integrate.php';
if (!stream_resolve_include_path($this->_file_name))
{
$this->_file_name = '';
}
break;
to:
Code: [Select]
				$this->_file_name = SUBSDIR . '/' . $this->_givenname . '.integrate.php';
if (!stream_resolve_include_path($this->_file_name))
{
$this->_file_name = ADDONSDIR . '/' . $this->_givenname . '/' . $this->_givenname . '.integrate.php';
if (!stream_resolve_include_path($this->_file_name))
{
$this->_file_name = '';
}
}
break;

Too many special cases... :-\
Bugs creator.
Features destroyer.
Template killer.

Re: Using the addon directory/autoloader

Reply #4

Quote- Your .integrate file must in in the /sources/subs directory. 
- All of you module files must be in sources/modules/SomeName/ directory.
ayup, the autoloader offers no flexibility there.

Idea for improvement: in the addons json manifest file, add extra/files/integrate to specify an integration file. (would certainly enable me to use one integration file. Currently, I have two: the standard one for registering all my hooks; and my own, which has the functions.)
LiveGallery - Simple gallery addon for ElkArte

Re: Using the addon directory/autoloader

Reply #5

Quote from: Spuds – - Your .integrate file must in in the /sources/subs directory. 
That could be an option as well I guess...
Probably I started designing it in a certain way and then changed my mind to have it in another, but being lazy I just changed the minimum to support both solutions.
Dunno, the original idea of the addons directory was to have everything there, but it's not yet possible I guess. :(
Bugs creator.
Features destroyer.
Template killer.

Re: Using the addon directory/autoloader

Reply #6

Quote from: live627 –
Quote- Your .integrate file must in in the /sources/subs directory. 
- All of you module files must be in sources/modules/SomeName/ directory.
ayup, the autoloader offers no flexibility there.
I think that my last orientation was to have namespaces to deal with all this kind of things:
\ElkArte => core, points to BOARDDIR/sources and sub-dir
\ElkArte\Addon => addons, points to BOARDDIR/Assons
from there, each addon should have a directory structure similar to that of BOARDDIR, so (if needed) have its own controllers\, admin\, subs\, whatever\).

The ultimate goal is to have each addon compartmentalized in its own directory, and delete the directory is enough to disable the addon.

Quote from: live627 – Idea for improvement: in the addons json manifest file, add extra/files/integrate to specify an integration file. (would certainly enable me to use one integration file. Currently, I have two: the standard one for registering all my hooks; and my own, which has the functions.)
I started using json-like files (see discoverIntegrations) to provide the stuff for the admin panel presentation. I'm not sure I would fetch a bunch of json at each and every page load... :-\
Bugs creator.
Features destroyer.
Template killer.

Re: Using the addon directory/autoloader

Reply #7

So, assuming one would want only one integration file. if it's moved to the subs directory then it doesn't automatically get pulled into the core features.

I guess the question then,  what's going to be the way to implement it?


Re: Using the addon directory/autoloader

Reply #9

Quoteif it's moved to the subs directory then it doesn't automatically get pulled into the core features.
So then you'll need to make an integration stub[1] in your addons dir. Or wait until @emanuele commits the above code to the repo.
literally an empty class with the same name
LiveGallery - Simple gallery addon for ElkArte


Re: Using the addon directory/autoloader

Reply #11

YAY! :D

 emanuele takes note to add it before RC1
Bugs creator.
Features destroyer.
Template killer.

Re: Using the addon directory/autoloader

Reply #12

I guess the next question then, because I'll admit to not quite understanding it, but is the namespace/directory stuff there and ready to use.

For instance, putting a controller file in addons/addon/controller?  Or does it have to go in the main controller directory for autoloading?  The only reason I was trying to use the addon directory is to keep all the files for the addon in one place, makes it easier to work on the addon and keep track of everything.

Re: Using the addon directory/autoloader

Reply #13

TL;DR: at the moment no.

Controllers in particular are expected to reside in sources/controllers (or admin) and change that may be tricky (actually it should be possible, but I don't think it's worth, because it's more a workaround than a proper way to handle them).
Bugs creator.
Features destroyer.
Template killer.

Re: Using the addon directory/autoloader

Reply #14

Using ElkArte/addons/addon as a namespace works fine for your controller, but I seem to recall having massive problems using a /controller dir, as it totally confused the autoloader.

A controller without a namespace can be loaded in any registered dir https://github.com/elkarte/Elkarte/blob/801ee9c95623a2e06992a6f7ce2151fddefb058b/sources/Autoloader.class.php#L370
LiveGallery - Simple gallery addon for ElkArte