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.
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();
}
Where did you put the file itself?
addons/Characters
/me is tempted to call it a bug
Unfortunately, I changed my mind too many times...
Try editing Autoloader.class.php changing:
$this->_file_name = SUBSDIR . '/' . $this->_givenname . '.integrate.php';
if (!stream_resolve_include_path($this->_file_name))
{
$this->_file_name = '';
}
break;
to:
$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... :-\
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.)
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. :(
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.
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... :-\
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?
Can you try: http://www.elkarte.net/community/index.php?topic=4204.msg30163#msg30163 ? :)
So then you'll need to make an integration stub in your addons dir. Or wait until
@emanuele commits the above code to the repo.
Yes with that code it does work, and I'm able to turn it on and off.
YAY! :D
/me takes note to add it before RC1
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.
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).
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