I would like to define a new type of Drupal message called "Workflow" and manage these messages separately from the standard Status, Error and Warning message types.

How can I add this new message type to the list of message types in the Rules config pages? In other words, add an extra OPTION to the SELECT list?

I've tried hook_form_alter and jQuery... but haven't had any luck.

Is there a way to do this?

Thanks,

Steve

Comments

thevine’s picture

Issue summary: View changes

Removed word

TR’s picture

Issue summary: View changes
Status: Active » Fixed

You will have to do this in a custom module.

  1. Copy rules_action_drupal_message_types() into your module and rename it. Edit this new function to contain the label for your new message type.
  2. Create a hook_rules_action_info_alter(&$actions). In this hook, modify the 'drupal_message' array - you want to set the contents of the 'options list' element to be the name of your function created in 1) instead of the default 'rules_action_drupal_message_types'. See rules.api.php for details.

Now when you use the drupal_message action your function will be used to provide the message options, instead of the default which only knows about Status, Warning, and Error.

TR’s picture

Here's a complete, working example module called rules_alter.

In rules.alter.info:

name = Rules Alter
description = Hook implementations to alter Rules
package = Rules
core = 7.x
dependencies[] = rules

In rules_alter.module:

<?php

/**
 * @file
 * Contains code which alters the operation of Rules.
 */

/**
 * Options list callback defining drupal_message types.
 */
function rules_alter_action_drupal_message_types() {
  return array(
    'status' => t('Status'),
    'warning' => t('Warning'),
    'error' => t('Error'),
    'workflow' => t('Workflow'),
  );
}

/**
 * Implements hook_rules_action_info_alter().
 *
 * Overrides the default drupal_message options list with our own.
 */
function rules_alter_rules_action_info_alter(&$actions) {
  $actions['drupal_message']['parameter']['type']['options list'] = 'rules_alter_action_drupal_message_types';
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

TR’s picture