1 action_example.module | action_example_node_unpublish_callback($node, $context) |
Action function for action_example_node_sticky_action.
Unpublish a node.
Parameters
object $node: A node object provided by the associated trigger.
array $context: Array with parameters for this action: depends on the trigger. The context is not used in this example.
Related topics
File
- modules/
examples/ action_example/ action_example.module, line 229 - Hook implementations for the Action Example module.
Code
function action_example_node_unpublish_callback($node, $context) {
if (function_exists('dsm')) {
dsm($node, 'action_example_node_sticky_action is firing. Here is the $node');
dsm($context, 'action_example_node_sticky_action is firing. Here is the $context');
}
global $user;
// Get the logged-in user.
$account = user_load($user->uid);
// Is the node created by this user? Unpublish it.
if ($account->uid == $node->uid) {
$node->status = 0;
$node->save();
watchdog('action',
'Set @type %title unpublished.',
array(
'@type' => node_type_get_name($node),
'%title' => $node->title,
)
);
backdrop_set_message(
t('Set @type %title unpublished.',
array(
'@type' => node_type_get_name($node),
'%title' => $node->title,
)
)
);
}
}