欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal hook_views_post_execute

shiping1 的头像

function hook_views_post_execute

7 views.api.phphook_views_post_execute(&$view)
6 docs.phphook_views_post_execute(&$view)

This hook is called right after the execute process. The query has been executed, but the pre_render() phase has not yet happened for handlers.

Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

Related topics

1 invocation of hook_views_post_execute()
view::execute in includes/view.inc
Execute the view's query.

File

 

docs/docs.php, line 673
This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

Code

function hook_views_post_execute(&$view) {
  // example code here
}
来自 https://api.drupal.org/api/views/docs!docs.php/function/hook_views_post_execute/6

 

 

function hook_views_post_execute

7 views.api.phphook_views_post_execute(&$view)
6 docs.phphook_views_post_execute(&$view)

This hook is called right after the execute process. The query has been executed, but the pre_render() phase has not yet happened for handlers.

Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

Parameters

$view: The view object about to be processed.

Related topics

1 invocation of hook_views_post_execute()

File

 

./views.api.php, line 915
Describe hooks provided by the Views module.

Code

function hook_views_post_execute(&$view) {
  // If there are more than 100 results, show a message that encourages the user
  // to change the filter settings.
  // (This action could be performed later in the execution process, but not
  // earlier.)
  if ($view->total_rows > 100) {
    drupal_set_message(t('You have more than 100 hits. Use the filter settings to narrow down your list.'));
  }
}

Comments

you can use the hook using following code sample:

<?php
function test_module_views_post_execute(&$view) {
   
$newResults = 'this is simple test text';
   
$view->result = $newResults;

}

?>

来自 https://api.drupal.org/api/views/views.api.php/function/hook_views_post_execute/7

 

function mymodule_views_post_execute(&$view) {
      if($view->name == "zohar_body_feed" && $view->args[0]==37) {
        global $user;
        $ir_chapters=db_query("SELECT ct.field_chapter_value AS chapter, n.nid, n.title FROM node AS n LEFT JOIN content_type_book_body AS ct ON n.nid=ct.nid LEFT JOIN term_node AS tn ON tn.nid=n.nid LEFT JOIN term_data AS td ON td.tid=tn.tid WHERE td.name='%s' AND n.type='zohar_body' ORDER BY ABS(chapter)",'Idra Raba');
        while($irc=db_fetch_object($ir_chapters)){
            $temp = new stdClass;
            $temp->nid=$irc->nid;
            $temp->node_data_field_chapter_field_chapter_value=$irc->chapter;
            $additions[]=$temp;
        }
        $results = array();
        foreach($view->result as $single_result) {
          if($single_result->node_data_field_chapter_field_chapter_value == 13) {
            foreach($additions as $addition){
                $results[] = $addition;
            }
          }
          $results[] = $single_result;
        }
        // replace the old result array
        $view->result = $results;
        if($user->uid==1) drupal_set_message('<pre>'.print_r($view,1).'</pre>');
      }
    }

 

 

function foo_views_post_execute(&$view) {
    $seen_rows = array();
    $newResults = array();
    for($i = 0; $i < count($view->result); ++$i) {
        if (!in_array($view->result[$i]->nid, $seen_rows)) {
            $newResults[] = $view->results[$i];
        }
        $seen_rows[] = $view->result[$i]->nid;
    }
    $view->result = $newResults;
}

 

有例子 http://drupalcontrib.org/api/drupal/contributions!views!views.api.php/function/hook_views_post_execu...

普通分类: