action_example_node_sticky_action

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 action_example_node_sticky_action($node, $context)

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

$node A node object provided by the associated trigger.

$context Array with the following elements:

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

Related topics

Code

examples/action_example/action_example.module, line 344

<?php
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)));
  }
}
?>