You are here

function action_example_node_sticky_action in Examples for Developers 7

Action function for action_example_node_sticky_action.

Promote and set sticky flag. This is the special action that has been customized using the configuration form, validated with the validation function, and submitted with the submit function.

Parameters

object $node: A node object provided by the associated trigger.

array $context: Array with the following elements:

  • 'author': username of the author's content this function will promote and set as sticky.

Related topics

1 string reference to 'action_example_node_sticky_action'
ActionExampleTestCase::testActionExample in action_example/action_example.test
Test Action Example.

File

action_example/action_example.module, line 343
Action definition example module.

Code

function action_example_node_sticky_action($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');
  }

  // Get the user configured for this special action.
  $account = user_load_by_name($context['author']);

  // Is the node created by this user? then promote and set as sticky.
  if ($account->uid == $node->uid) {
    $node->promote = NODE_PROMOTED;
    $node->sticky = NODE_STICKY;
    watchdog('action', 'Set @type %title to sticky and promoted by special action for user %username.', array(
      '@type' => node_type_get_name($node),
      '%title' => $node->title,
      '%username' => $account->name,
    ));
    drupal_set_message(t('Set @type %title to sticky and promoted by special action for user %username.', array(
      '@type' => node_type_get_name($node),
      '%title' => $node->title,
      '%username' => $account->name,
    )));
  }
}