scmsg-8.x-1.1/simple_cool_message.module

simple_cool_message.module
<?php

/**
 * @file
 * simple_cool_message.module
 * Provides cool notification messages.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function simple_cool_message_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the sinceago module.
    case 'help.page.simple_cool_message':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';      
	  $output .= check_markup(file_get_contents(dirname(__FILE__) . "/README.txt"));
      return $output;
    default:
  }
}


/**
 * Implements hook_theme().
 */
function simple_cool_message_theme($existing, $type, $theme, $path) {
  return array(    
    'simple_cool_messages' => array(
      'variables' => array('title' => NULL, 'type' => NULL, 'messages' => NULL),
      'template' => 'simple-cool-messages',
    ),
  );
}

/**
 * Process variables for cool-messages.tpl.php.
 *
 * The $variables array contains the following arguments:
 * - $title
 * - $type
 * - $messages
 *
 * @see cool-messages.tpl.php
 */
function template_preprocess_simple_cool_messages(&$variables) {
  $status_heading = array(
    'status'  => t('Status message'), 
    'error'   => t('Error message'), 
    'warning' => t('Warning message'),
  );  
  $messages = $variables['messages'];
  $output = '';
  if (!empty($status_heading[$variables['type']])) {
    $variables['title'] = $status_heading[$variables['type']];
  }  
  if (count($messages) > 1) {
    $output .= " <ul>\n";
    foreach ($messages as $message) {
      $output .= '  <li>' . $message . "</li>\n";
    }
    $output .= " </ul>\n";
  }
  else {
    $output .= $messages[0];
  }
  $variables['messages'] = $output;
}

/**
 * Implements hook_page_attachments().
 */
function simple_cool_message_page_attachments(array &$attachments) {
  // Unconditionally attach an asset to the page.	
  $attachments['#attached']['library'][] = 'simple_cool_message/simple_cool_message.library';
  
  $config = \Drupal::config('simple_cool_message.simple_cool_message');
  
  $settings = [
    'simple_coolmessage_enable' => $config->get('simple_coolmessage_enable'),
    'status_color' => $config->get('status_color'),
    'info_color' => $config->get('info_color'),
    'warning_color' => $config->get('warning_color'),
    'error_color' => $config->get('error_color')    
  ];

  $attachments['#attached']['drupalSettings']['coll_message'] = $settings;
  
}

/**
 * Implements hook_theme_registry_alter().
 */
function simple_cool_message_theme_registry_alter(&$theme_registry) {
  $coolmessage_enable = \Drupal::config('simple_cool_message.simple_cool_message')->get('simple_coolmessage_enable');  
  if($coolmessage_enable){
	$theme_registry['status_messages']['function'] = 'simple_cool_message_status_messages';  
  }
}


/**
 * Show themed messages.
 */
function simple_cool_message_status_messages($variables) {
  
  $output = '';
  $output .= "<div id=\"messages\">\n";
  $output .= "<div id=\"messages-box\">\n";
  foreach ($variables['message_list'] as $type => $messages) {    
    $template = ['#theme' => 'simple_cool_messages', '#type' => $type,  '#messages' => $messages,];
    $output .= \Drupal::service('renderer')->render($template); 
  }
  $output .= "</div>\n";
  $output .= "</div>\n";
  return $output;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc