New API questions (libraries, config, js/css)

So, I've started upgrading my plugins to 1.8 and it looks like a great platform. I have a couple of questions as to the new api/view system. Want to do everything right from the beginning:

1. Libraries

What's the best place to register a library - activate.php or init?

What global vars are available in activate.php? is there $vars['entity'] of some sort?

What happens when I load a library? Can it be done in init or should I load it only when I want to use a certain function from the library?

2. global $CONFIG;

Documentation suggests that we do not use $CONFIG in the plugins, but it seems that some of the core plugins still do. What's the best practice here? Are there any alternative holders of config information?

3. js/css

Can js/css be registered from anywhere, or should be done in init only?

4. contexts

I notice some changes in the context api. Any documentation available on that somewhere?

5. css question for plugin authors

Are you going to update your css selectors? In my plugins, should I keep support for both 1.7 and 1.8 css?

  • 1. activate.php (if I remember correctly) is only run when a plugin is activated. PHP libraries should usually be registered in your init function in start.php. You can load a library anywhere and anytime. Loading a library just means that its code is included and made available. There is the tradeoff between loading the library on every page load and loading it only when needed - time, memory, code complexity

    2. The core plugins should not be using $CONFIG anymore. I know the search plugin and the notifications plugin has not been updated for 1.8 (they work but the code is still 1.0-1.7 style). You can access config information through the new config functions (elgg_get_config, elgg_set_config, elgg_save_config)

    3. Recommend registering in the init function but can be loaded anywhere

    You should take a look at the blog posts: http://blog.elgg.org/pg/search/?q=elgg1.8&search_type=tags

    and the wiki:

    http://docs.elgg.org/wiki/Updating_plugins_for_Elgg_1.8

  • Thanks, Cash.

    Updating plugins stab is quite helpful. Was a good place to start.

    One more question, what's the status of ajaxify? It seems it didn't make it to the core of 1.8

  • Evan can give you a better answer on that. I think all the non-experimental stuff was integrated. Take a look at the js directory.

  • Ah, awesome! Found it. It's making life so much easier!

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.