/** * Expected plugins list * @return array */ public function pluginsListDataProvider() { $plugins = theme_plugin_get_enabled_plugins(); $datas = array(); foreach ($plugins as $plugin_id => $plugin_datas) { $datas[] = array($plugin_id); } return $datas; }
/** * Invoke all plugins for a specific drupal hook. It will look for all * plugins responding to a hook and call them. * * - For preprocess, variables are passed by reference so several plugins * may respond to one hook. * * - For theme functions, only one plugin may respond, so if * several plugins want to return a theme override, we return only the last... * * For now, it's up to user to not use plugins overriding the same drupal theme function */ function theme_plugins_invoke($hook, &$arg1 = array(), &$arg2 = array(), &$arg3 = array(), &$arg4 = array()) { $plugins = theme_get_plugins(); $plugins_enabled = theme_plugin_get_enabled_plugins(); $html = NULL; // static cache for plugin instances, we make sure each plugin is // instanciated only one time per http request inside this function. static $factory = array(); // call only enabled plugins. foreach ($plugins_enabled as $plugin_id) { // get full plugin infos from info file. $plugin_infos = $plugins[$plugin_id]; // plugin id is corresponding file / class name. // for okcdesign_preprocess_page, call method hook_preprocess_page() in plugin class. $method = str_replace('okcdesign' . '', 'hook', $hook); // if plugins declared a method to fire for this particular hook, call it. if (isset($plugin_infos['hooks']) && in_array($method, $plugin_infos['hooks'])) { // put plugin object in the factory if not already in. if (empty($factory[$plugin_id])) { $factory[$plugin_id] = new $plugin_id(); } // Let our phpunit tests know if called method has not been found. $html = $factory[$plugin_id]->{$method}($arg1, $arg2, $arg3, $arg4); } } // this should contain html when this function is called from a theme hook function. return $html; }
function test_theme_plugin_get_enabled_plugins() { // Always do our test on okcdesign rather than default active theme. // this if for theme_get_setting function $GLOBALS['theme_key'] = 'okcdesign'; $plugins = theme_get_plugins(); // disable all plugins $theme_settings = variable_get("theme_okcdesign_settings"); foreach ($plugins as $plugin_id => $datas) { $theme_settings["theme_plugin_{$plugin_id}"] = 0; } variable_set("theme_okcdesign_settings", $theme_settings); drupal_static_reset('theme_get_setting'); // each plugin should be disabled now... foreach ($plugins as $plugin_id => $datas) { $this->assertFalse(theme_plugin_is_enabled($plugin_id)); } $this->assertEmpty(theme_plugin_get_enabled_plugins()); // re-enable only required plugins : $theme_settings = variable_get("theme_okcdesign_settings"); $required_plugins = $this->requiredPlugins(); foreach ($required_plugins as $plugin_id) { $theme_settings["theme_plugin_{$plugin_id}"] = 1; } variable_set("theme_okcdesign_settings", $theme_settings); drupal_static_reset('theme_get_setting'); // each required plugin should be enabled now. foreach ($required_plugins as $plugin_id) { $this->assertTrue(theme_plugin_is_enabled($plugin_id)); } // theme_get_enabled_plugins must return exactly the same plugins : $this->assertSame(ksort($required_plugins), ksort(array_keys(theme_plugin_get_enabled_plugins()))); }