You are here

nicemessages.module in Nice messages 8.2

Same filename and directory in other branches
  1. 7.2 nicemessages.module
  2. 7 nicemessages.module

File

nicemessages.module
View source
<?php

/**
 * Implement hook_element_info_alter().
 */
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();
  }
}

/**
 *  Implements hook_preprocess_page().
 */
function nicemessages_preprocess_page(&$vars) {
  if (nicemessages_enabled()) {
    if (nicemessages_pages_visibility() == FALSE) {
      return;
    }

    // Do not display messages in standard way,
    $vars['show_messages'] = false;

    // display them with jGrowl
    // nicemessages_get_messages();
    // kint($vars);
  }
}
function nicemessages_enabled() {

  // *todo: Implement.
  return TRUE;
}
function nicemessages_pages_visibility() {

  // *todo: Implement.
  return TRUE;
}

/**
 *  Save messages to js settings.
 */
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;
}

Functions