Same name and namespace in other branches
  1. 7.x modules/system/system.module \system_message_action()

A configurable Drupal action. Sends a message to the current user's screen.

File

modules/system/system.module, line 1855
Configuration system that lets administrators modify the workings of the site.

Code

function system_message_action(&$object, $context = array()) {
  global $user;
  $variables = array(
    '%site_name' => variable_get('site_name', 'Drupal'),
    '%username' => $user->name ? $user->name : variable_get('anonymous', t('Anonymous')),
  );

  // This action can be called in any context, but if placeholders
  // are used a node object must be present to be the source
  // of substituted text.
  switch ($context['hook']) {
    case 'nodeapi':

      // Because this is not an action of type 'node' the node
      // will not be passed as $object, but it will still be available
      // in $context.
      $node = $context['node'];
      break;

    // The comment hook also provides the node, in context.
    case 'comment':
      $comment = $context['comment'];
      $node = node_load($comment->nid);
      break;
    case 'taxonomy':
      $vocabulary = taxonomy_vocabulary_load($object->vid);
      $variables = array_merge($variables, array(
        '%term_name' => check_plain($object->name),
        '%term_description' => filter_xss_admin($object->description),
        '%term_id' => $object->tid,
        '%vocabulary_name' => check_plain($vocabulary->name),
        '%vocabulary_description' => filter_xss_admin($vocabulary->description),
        '%vocabulary_id' => $vocabulary->vid,
      ));
      break;
    default:

      // We are being called directly.
      $node = $object;
  }
  if (isset($node) && is_object($node)) {
    $variables = array_merge($variables, array(
      '%uid' => $node->uid,
      '%node_url' => url('node/' . $node->nid, array(
        'absolute' => TRUE,
      )),
      '%node_type' => check_plain(node_get_types('name', $node)),
      '%title' => check_plain($node->title),
      '%teaser' => check_markup($node->teaser, $node->format, FALSE),
      '%body' => check_markup($node->body, $node->format, FALSE),
    ));
  }
  $context['message'] = strtr(filter_xss_admin($context['message']), $variables);
  drupal_set_message($context['message']);
}