| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Contains the view analyze tool code. 6 * 7 * This tool is a small plugin manager to perform analysis on a view and 8 * report results to the user. This tool is meant to let modules that 9 * provide data to Views also help users properly use that data by 10 * detecting invalid configurations. Views itself comes with only a 11 * small amount of analysis tools, but more could easily be added either 12 * by modules or as patches to Views itself. 13 */ 14 15 /** 16 * Analyze a review and return the results. 17 * 18 * @return 19 * An array of analyze results organized into arrays keyed by 'ok', 20 * 'warning' and 'error'. 21 */ 22 function views_analyze_view(&$view) { 23 $view->init_display(); 24 $messages = module_invoke_all('views_analyze', $view); 25 26 return $messages; 27 } 28 29 /** 30 * Format the analyze result into a message string. 31 * 32 * This is based upon the format of drupal_set_message which uses separate 33 * boxes for "ok", "warning" and "error". 34 */ 35 function views_analyze_format_result($view, $messages) { 36 if (empty($messages)) { 37 $messages = array(views_ui_analysis(t('View analysis can find nothing to report.'), 'ok')); 38 } 39 40 $types = array('ok' => array(), 'warning' => array(), 'error' => array()); 41 foreach ($messages as $message) { 42 if (empty($types[$message['type']])) { 43 $types[$message['type']] = array(); 44 } 45 $types[$message['type']][] = $message['message']; 46 } 47 48 $output = ''; 49 foreach ($types as $type => $messages) { 50 $message = ''; 51 if (count($messages) > 1) { 52 $message = theme('item_list', $messages); 53 } 54 else if ($messages) { 55 $message = array_shift($messages); 56 } 57 58 if ($message) { 59 $output .= "<div class=\"$type\">$message</div>"; 60 } 61 } 62 63 return $output; 64 } 65 66 /** 67 * Format an analysis message. 68 * 69 * This tool should be called by any module responding to the analyze hook 70 * to properly format the message. It is usually used in the form: 71 * @code 72 * $ret[] = views_ui_analysis(t('This is the message'), 'ok'); 73 * @endcode 74 * 75 * The 'ok' status should be used to provide information about things 76 * that are acceptable. In general analysis isn't interested in 'ok' 77 * messages, but instead the 'warning', which is a category for items 78 * that may be broken unless the user knows what he or she is doing, 79 * and 'error' for items that are definitely broken are much more useful. 80 * 81 * @param $messages 82 * The message to report. 83 * @param $type 84 * The type of message. This should be "ok", "warning" or "error". Other 85 * values can be used but how they are treated by the output routine 86 * is undefined. 87 */ 88 function views_ui_analysis($message, $type = 'error') { 89 return array('message' => $message, 'type' => $type); 90 } 91 92 /** 93 * Implementation of hook_views_analyze(). 94 * 95 * This is the basic views analysis that checks for very minimal problems. 96 * There are other analysis tools in core specific sections, such as 97 * node.views.inc as well. 98 */ 99 function views_ui_views_analyze($view) { 100 $ret = array(); 101 // Check for something other than the default display: 102 if (count($view->display) < 2) { 103 $ret[] = views_ui_analysis(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning'); 104 } 105 106 return $ret; 107 } 108
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |