2
// $Id: analyze.inc,v 1.1 2008/10/28 22:50:00 merlinofchaos Exp $
6
* Contains the view analyze tool code.
8
* This tool is a small plugin manager to perform analysis on a view and
9
* report results to the user. This tool is meant to let modules that
10
* provide data to Views also help users properly use that data by
11
* detecting invalid configurations. Views itself comes with only a
12
* small amount of analysis tools, but more could easily be added either
13
* by modules or as patches to Views itself.
17
* Analyze a review and return the results.
20
* An array of analyze results organized into arrays keyed by 'ok',
21
* 'warning' and 'error'.
23
function views_analyze_view(&$view) {
24
$view->init_display();
25
$messages = module_invoke_all('views_analyze', $view);
31
* Format the analyze result into a message string.
33
* This is based upon the format of drupal_set_message which uses separate
34
* boxes for "ok", "warning" and "error".
36
function views_analyze_format_result($view, $messages) {
37
if (empty($messages)) {
38
$messages = array(views_ui_analysis(t('View analysis can find nothing to report.'), 'ok'));
41
$types = array('ok' => array(), 'warning' => array(), 'error' => array());
42
foreach ($messages as $message) {
43
if (empty($types[$message['type']])) {
44
$types[$message['type']] = array();
46
$types[$message['type']][] = $message['message'];
50
foreach ($types as $type => $messages) {
52
if (count($messages) > 1) {
53
$message = theme('item_list', $messages);
56
$message = array_shift($messages);
60
$output .= "<div class=\"$type\">$message</div>";
68
* Format an analysis message.
70
* This tool should be called by any module responding to the analyze hook
71
* to properly format the message. It is usually used in the form:
73
* $ret[] = views_ui_analysis(t('This is the message'), 'ok');
76
* The 'ok' status should be used to provide information about things
77
* that are acceptable. In general analysis isn't interested in 'ok'
78
* messages, but instead the 'warning', which is a category for items
79
* that may be broken unless the user knows what he or she is doing,
80
* and 'error' for items that are definitely broken are much more useful.
83
* The message to report.
85
* The type of message. This should be "ok", "warning" or "error". Other
86
* values can be used but how they are treated by the output routine
89
function views_ui_analysis($message, $type = 'error') {
90
return array('message' => $message, 'type' => $type);
94
* Implementation of hook_views_analyze().
96
* This is the basic views analysis that checks for very minimal problems.
97
* There are other analysis tools in core specific sections, such as
98
* node.views.inc as well.
100
function views_ui_views_analyze($view) {
102
// Check for something other than the default display:
103
if (count($view->display) < 2) {
104
$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');