summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2009-06-17 18:25:03 (GMT)
committer Earl Miles2009-06-17 18:25:03 (GMT)
commita971a8d62ca2b3320da0c20ac923a67947117523 (patch)
treed98aa141166d5f8977895a27c254e688a27918bb
parentc7e8b287b04a71728536dd2f52f826f2560af777 (diff)
Implement a post_render hook (for themes too) and cache method.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--docs/docs.php28
-rw-r--r--includes/view.inc20
-rw-r--r--plugins/views_plugin_cache.inc22
4 files changed, 72 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index c14107c..9e07d8d 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,4 +1,6 @@
CHANGELOG for Views 2 for Drupal 6
+ Other changes:
+ o Implement a post_render hook (for themes too) and cache method.
Views 2.6
Bugs fixed:
diff --git a/docs/docs.php b/docs/docs.php
index 8e8bcbd..40aed91 100644
--- a/docs/docs.php
+++ b/docs/docs.php
@@ -574,12 +574,40 @@ function hook_views_pre_execute(&$view) {
*
* Adding output to the view cam be accomplished by placing text on
* $view->attachment_before and $view->attachment_after
+ *
+ * This hook can be utilized by themes.
*/
function hook_views_pre_render(&$view) {
// example code here
}
/**
+ * Post process any rendered data.
+ *
+ * This can be valuable to be able to cache a view and still have some level of
+ * dynamic output. In an ideal world, the actual output will include HTML
+ * comment based tokens, and then the post process can replace those tokens.
+ *
+ * Example usage. If it is known that the view is a node view and that the
+ * primary field will be a nid, you can do something like this:
+ *
+ * <!--post-FIELD-NID-->
+ *
+ * And then in the post render, create an array with the text that should
+ * go there:
+ *
+ * strtr($output, array('<!--post-FIELD-1-->', 'output for FIELD of nid 1');
+ *
+ * All of the cached result data will be available in $view->result, as well,
+ * so all ids used in the query should be discoverable.
+ *
+ * This hook can be utilized by themes.
+ */
+function hook_views_post_render(&$view, &$output, &$cache) {
+
+}
+
+/**
* Stub hook documentation
*
* This hook should be placed in MODULENAME.views.inc and it will be auto-loaded.
diff --git a/includes/view.inc b/includes/view.inc
index eb2ed65..bdbf7b7 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -818,6 +818,12 @@ class view extends views_db_object {
$function($this);
}
+ // Let the theme play too, because pre render is a very themey thing.
+ $function = $GLOBALS['theme']) . '_views_pre_render';
+ if (function_exists($function) {
+ $function($this, $this->display_handler->output, $cache);
+ }
+
// Give field handlers the opportunity to perform additional queries
// using the entire resultset prior to rendering.
if ($this->style_plugin->uses_fields()) {
@@ -833,6 +839,20 @@ class view extends views_db_object {
}
}
+ $cache->post_render($this, $this->display_handler->output);
+
+ // Let modules modify the view output after it is rendered.
+ foreach (module_implements('views_post_render') as $module) {
+ $function = $module . '_views_post_render';
+ $function($this, $this->display_handler->output, $cache);
+ }
+
+ // Let the theme play too, because post render is a very themey thing.
+ $function = $GLOBALS['theme']) . '_views_post_render';
+ if (function_exists($function) {
+ $function($this, $this->display_handler->output, $cache);
+ }
+
if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
$this->end_query_capture();
}
diff --git a/plugins/views_plugin_cache.inc b/plugins/views_plugin_cache.inc
index 20706e3..ce35311 100644
--- a/plugins/views_plugin_cache.inc
+++ b/plugins/views_plugin_cache.inc
@@ -135,6 +135,28 @@ class views_plugin_cache extends views_plugin {
}
/**
+ * Post process any rendered data.
+ *
+ * This can be valuable to be able to cache a view and still have some level of
+ * dynamic output. In an ideal world, the actual output will include HTML
+ * comment based tokens, and then the post process can replace those tokens.
+ *
+ * Example usage. If it is known that the view is a node view and that the
+ * primary field will be a nid, you can do something like this:
+ *
+ * <!--post-FIELD-NID-->
+ *
+ * And then in the post render, create an array with the text that should
+ * go there:
+ *
+ * strtr($output, array('<!--post-FIELD-1-->', 'output for FIELD of nid 1');
+ *
+ * All of the cached result data will be available in $view->result, as well,
+ * so all ids used in the query should be discoverable.
+ */
+ function post_render(&$view, &$output) { }
+
+ /**
* Start caching javascript, css and other out of band info.
*
* This takes a snapshot of the current system state so that we don't