messages_alter.module in Custom Submit Messages 7.x
Same filename and directory in other branches
The main module file for Status Messages Alter.
File
messages_alter/messages_alter.moduleView source
<?php
/**
* @file
* The main module file for Status Messages Alter.
*/
/**
* Implements hook_permission().
*/
function messages_alter_permission() {
return array(
'administer messages alter settings',
);
}
/**
* Implements hook_menu().
*/
function messages_alter_menu() {
$items = array();
$items['admin/config/messages_alter'] = array(
'title' => 'Messages Alter Settings',
'description' => 'Administer settings for the messages alter module.',
'page callback' => 'messages_alter_settings_page',
'access arguments' => array(
'administer messages alter settings',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_theme().
*/
function messages_alter_theme($existing, $type, $theme, $path) {
return array(
'messages_alter_status_messages' => array(
'variables' => array(
'variables' => NULL,
'theme_function' => NULL,
),
),
'messages_alter_settings_page' => array(
'variables' => NULL,
),
);
}
/**
* Implements hook_theme_registry_alter().
*/
function messages_alter_theme_registry_alter(&$theme_registry) {
if (!variable_get('messages_alter_theme_altered', FALSE)) {
variable_set('messages_alter_theme_altered', $theme_registry['status_messages']['function']);
}
$theme_registry['status_messages']['function'] = 'theme_messages_alter_alter';
}
/**
* Theme function
* This is the theme function that overrides
* theme('status_messages');
*/
function theme_messages_alter_alter($variables) {
messages_alter_invoke_message_alter();
$output = theme('messages_alter_status_messages', array(
'variables' => $variables,
'theme_function' => variable_get('messages_alter_theme_altered', FALSE),
));
return $output;
}
/**
* Theme function
* Using a theme function here so that if someone wants to overide it, they can.
*/
function theme_messages_alter_status_messages($variables) {
$output = '';
$theme_function = isset($variables['theme_function']) && !empty($variables['theme_function']) ? $variables['theme_function'] : 'theme_status_messages';
$output = $theme_function($variables['variables']);
return $output;
}
/**
* Loops through invokes all the modules that implement hook_message_alter().
*/
function messages_alter_invoke_message_alter() {
// let's not confuse this object with
// the Drupal session array
// we're just going to add functionality
// with a class because I think
// it will be more fun this way
$messages = messages_alter_get_messages();
// this function speaks for itself
drupal_alter('message', $messages);
// we're cleaning this because
// sometimes there are fragmented
// messages after someone calls
// the remove method of the messages object
$messages
->clean();
}
/**
* The getter for your adapted messages object
*/
function messages_alter_get_messages($reset = FALSE) {
static $return;
if (!isset($return) || $reset) {
if (!isset($_SESSION['messages'])) {
$_SESSION['messages'] = array();
}
// I'm doing a "version" thingy here because
// I've always thought it was rude for
// modules to upgrade and then break
// for existing users..
// So I'm not going to break you :)
// I hope..
$version = check_plain(variable_get('messages_alter_version', '6.x-1.3'));
$path = drupal_get_path('module', 'messages_alter');
require_once $path . '/lib/MessagesAlter.' . $version . '.php';
$return = new MessagesAlter($_SESSION['messages']);
}
return $return;
}
/**
* Implements hook_message_alter().
*
* You would do something like this
* with your custom module:
*
* yourmodule_message_alter(&$messages) {
*
* }
*
*/
function messages_alter_message_alter(&$messages) {
// remove buggy Drupal 7 messages
//$matches = $messages->contains()
}
// end HOOKS
// Theme Callbacks
function theme_messages_alter_settings_page() {
$output = '';
$output .= drupal_get_form('messages_alter_set_latest_form');
$output .= drupal_get_form('messages_alter_settings_form');
return $output;
}
// Form Callbacks
function messages_alter_set_latest_form() {
$form = array();
$form['latest'] = array(
'#type' => 'fieldset',
'#title' => t('Update'),
'#description' => t('Click this button once you\'ve gone through and made sure your modules are compatible with the latest MessagesAlter object.'),
);
$form['latest']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update to latest version'),
);
return $form;
}
function messages_alter_set_latest_form_submit($form, &$form_state) {
// this is set in the hook_update_N() function
// it doesn't do anything once it's already been updated
variable_set('messages_alter_version', variable_get('messages_alter_version_latest', '6.x-1.3'));
// give the user some feedback so he/she feels good about him/her self
drupal_set_message(t('MessagesAlter object has been updated to the latest version.'));
}
function messages_alter_settings_form() {
$form = array();
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced Settings'),
'#description' => t('Only modify the following field(s) if you know what you\'re doing.'),
);
$version = messages_alter_version();
$form['advanced']['messages_alter_version'] = array(
'#type' => 'select',
'#title' => t('What version of the MessageAlter object would you like to use?'),
'#description' => t('In hopes of not breaking your site when future releases are released, we have versioned out the MessageAlter class that is used within the API.'),
'#default_value' => check_plain($version),
'#options' => array(
'6.x-1.3' => t('6.x-1.3'),
),
);
return system_settings_form($form);
}
// Page Callbacks
function messages_alter_settings_page() {
// doing it this way in case someone
// wants to change the HTML
return theme('messages_alter_settings_page');
}
// Helper Functions
/**
* Tries to grab the current version
* It'll only return "rookie" if
* it's the first install and they haven't
* upgraded yet. All new installs are set
* correctly.
*/
function messages_alter_version() {
return variable_get('messages_alter_version', '6.x-1.3');
}
Functions
Name![]() |
Description |
---|---|
messages_alter_get_messages | The getter for your adapted messages object |
messages_alter_invoke_message_alter | Loops through invokes all the modules that implement hook_message_alter(). |
messages_alter_menu | Implements hook_menu(). |
messages_alter_message_alter | Implements hook_message_alter(). |
messages_alter_permission | Implements hook_permission(). |
messages_alter_settings_form | |
messages_alter_settings_page | |
messages_alter_set_latest_form | |
messages_alter_set_latest_form_submit | |
messages_alter_theme | Implements hook_theme(). |
messages_alter_theme_registry_alter | Implements hook_theme_registry_alter(). |
messages_alter_version | Tries to grab the current version It'll only return "rookie" if it's the first install and they haven't upgraded yet. All new installs are set correctly. |
theme_messages_alter_alter | Theme function This is the theme function that overrides theme('status_messages'); |
theme_messages_alter_settings_page | |
theme_messages_alter_status_messages | Theme function Using a theme function here so that if someone wants to overide it, they can. |