View source
<?php
function nicemessages_element_info_alter(array &$types) {
if (isset($types['status_messages'])) {
drupal_set_message('TEST');
$types['status_messages']['#attached']['library'][] = 'nicemessages/nicemessages';
$types['status_messages']['#attached']['drupalSettings']['nicemessages'] = nicemessages_get_messages();
}
}
function nicemessages_preprocess_page(&$vars) {
if (nicemessages_enabled()) {
if (nicemessages_pages_visibility() == FALSE) {
return;
}
$vars['show_messages'] = false;
}
}
function nicemessages_enabled() {
return TRUE;
}
function nicemessages_pages_visibility() {
return TRUE;
}
function nicemessages_get_messages() {
$items = array();
foreach (drupal_get_messages() as $type => $messages) {
foreach ($messages as $key => $message) {
$item = array(
'type' => $type,
'content' => $message,
'life' => 6000,
'glue' => 'after',
'speed' => 'slow',
);
$items[] = $item;
}
}
$settings = array(
'position' => 'bottom-left',
'items' => $items,
);
return $settings;
}