public function Analyzer::formatMessages in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Analyzer.php \Drupal\views\Analyzer::formatMessages()
Formats the analyze result into a message string.
This is based upon the format of drupal_set_message which uses separate boxes for "ok", "warning" and "error".
File
- core/
modules/ views/ src/ Analyzer.php, line 63 - Contains \Drupal\views\Analyzer.
Class
- Analyzer
- This tool is a small plugin manager to perform analysis on a view and report results to the user. This tool is meant to let modules that provide data to Views also help users properly use that data by detecting invalid configurations. Views itself…
Namespace
Drupal\viewsCode
public function formatMessages(array $messages) {
if (empty($messages)) {
$messages = array(
static::formatMessage(t('View analysis can find nothing to report.'), 'ok'),
);
}
$types = array(
'ok' => array(),
'warning' => array(),
'error' => array(),
);
foreach ($messages as $message) {
if (empty($types[$message['type']])) {
$types[$message['type']] = array();
}
$types[$message['type']][] = $message['message'];
}
$output = '';
foreach ($types as $type => $messages) {
$type .= ' messages';
$message = '';
if (count($messages) > 1) {
$item_list = array(
'#theme' => 'item_list',
'#items' => $messages,
);
$message = drupal_render($item_list);
}
elseif ($messages) {
$message = array_shift($messages);
}
if ($message) {
$output .= "<div class=\"{$type}\">{$message}</div>";
}
}
return $output;
}