system_message_action
modules/system/system.module, строка 1763
- Версии
- 6
system_message_action(&$object, $context = array())
A configurable Drupal action. Sends a message to the current user's screen.
Код
<?php
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' => $object->name,
'%term_description' => $object->description,
'%term_id' => $object->tid,
'%vocabulary_name' => $vocabulary->name,
'%vocabulary_description' => $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' => filter_xss($node->title),
'%teaser' => filter_xss($node->teaser),
'%body' => filter_xss($node->body),
)
);
}
$context['message'] = strtr($context['message'], $variables);
drupal_set_message($context['message']);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии