Permalink
Browse files

tagmodules index updated. Seems to work. More tests to come

  • Loading branch information...
1 parent d4f85a7 commit 1a8270ba50d8b16fb2d1c094831f6deaba1ffa70 @shakty committed Apr 21, 2012
Showing with 89 additions and 6 deletions.
  1. +1 −1 includes/api/api.inc
  2. +3 −2 includes/core/common.inc
  3. +85 −3 patterns.module
View
@@ -49,7 +49,7 @@ function patterns_api_is_reserved_word($word = NULL) {
*
*/
function patterns_api_build_tagmodules_index($tag = NULL, $data = NULL, $key = NULL) {
- return patterns_get_tagmodules_index($tag, NULL, $key);
+ return patterns_get_tagmodules_index(NULL, NULL, $tag, $key); // TODO adjust
}
/**
* Builds up an associative array of modules and exposed tags.
View
@@ -28,7 +28,7 @@ function patterns_prepare_action(&$action, &$data, $actions_map) {
}
// Keep a list of which modules handle what tags.
- $tag_modules = patterns_get_tagmodules_index(NULL, $data);
+ $tag_modules = patterns_get_tagmodules_index($data);
$errors = array();
@@ -105,7 +105,8 @@ function patterns_implement_action($action, $data, &$identifiers, $place = 0, $a
$msg = '';
// Refresh the list of forms based on the data we have.
- $tag_info = patterns_get_tagmodules_index($data['tag'], $data);
+ $tagmodules = patterns_get_tagmodules_index($data);
+ $tag_info = patterns_tagmodules_filter($tagmodules, $data['tag']);
$form_ids = $tag_info[$action];
/*
View
@@ -720,7 +720,7 @@ function patterns_start_engine($pattern, $params = array(), $mode = 'batch') {
*/
function patterns_invoke($hook, $action, &$data = NULL, $form_id = NULL, &$a = NULL) {
- $tag_modules = patterns_get_tagmodules_index(NULL, $data); // TODO: check the parameters
+ $tag_modules = patterns_get_tagmodules_index($data); // TODO: check the parameters
// Unsetting it while the module performs operations.
$tag = $data['tag'];
@@ -822,8 +822,90 @@ function patterns_get_tagmodules_index_old($tag_name = NULL, $data = NULL, $id =
}
}
-function patterns_get_tagmodules_index($tag_name = NULL, $data = NULL, $key = NULL) {
- static $tag_modules;
+/**
+ *
+ * @param $data
+ * @param $tag
+ * @param $key
+ */
+function patterns_get_tagmodules_index($data = NULL, $reset = FALSE) {
+
+ $tagmodules = &drupal_static(__FUNCTION__);
+
+ // Index not yet built or forced rebuilt
+ if ($reset || empty($tagmodules)) {
+
+ $tagmodules = array();
+ // Get a list of tags and their modules.
+ foreach (module_implements('patterns') as $module) {
+ _patterns_add_module_to_tagmodules($module, $tagmodules, $data);
+ //$tags = module_invoke($module, 'patterns', $data);
+ // _patterns_add_module_to_tags($module, $tags);
+ // $tagmodules = array_merge($tagmodules, $tags);
+ //foreach ($tags as $tagname => $value) {
+ // Add the reference to the module within the information which each
+ // module is already returning
+ // $value['module'] = $module;
+ // $tagmodules[$tagname] = $value;
+ //}
+ }
+ }
+ // We may need to rebuild the index just for the specific tag
+ else if (!empty($data)) {
+ $tag_name = $data['tag'];
+ $module = $tagmodules[$tag_name]['module'];
+ if (!empty($module)) {
+ _patterns_add_module_to_tagmodules($module, $tagmodules, $data);
+ //$update = module_invoke($module, 'patterns', $data);
+ //_patterns_add_module_to_tags($module, $update);
+ //$tagmodules = array_merge($tagmodules, $update);
+ }
+ }
+
+ // All values from all tags
+ return $tagmodules;
+}
+
+function _patterns_add_module_to_tagmodules($module, &$tagmodules, $data = NULL) {
+ $tags = module_invoke($module, 'patterns', $data);
+ _patterns_add_module_to_tags($module, $tags);
+ $tagmodules = array_merge($tagmodules, $tags);
+}
+
+function _patterns_add_module_to_tags($module, &$tags) {
+ foreach ($tags as $tagname => $value) {
+ $tags[$tagname]['module'] = $module;
+ }
+}
+
+
+function patterns_tagmodules_filter($tagmodules, $tag, $key) {
+ if (empty($tagmodules)) return FALSE;
+
+ // Part of tag
+ if (!empty($tag) && !empty($key)) {
+ return $tagmodules[$tag][$key];
+ }
+ // Full tag
+ if (!empty($tag)) {
+ return $tagmodules[$tag];
+ }
+
+ // All the values of key=$key from all tags
+ if (!empty($key)) {
+ $out = array();
+ foreach ($tagmodules as $tagname => $value) {
+ if (isset($value[$key])) {
+ $out[$value['module']][$tagname] = $value[$key];
+ }
+ }
+ return $out;
+ }
+}
+
+function patterns_get_tagmodules_index_medium($tag_name = NULL, $data = NULL, $key = NULL) {
+
+ $tag_modules = &drupal_static(__FUNCTION__);
// Index not yet built
if (empty($tag_modules)) {

0 comments on commit 1a8270b

Please sign in to comment.