function node_assign_owner_action

Assigns ownership of a node to a user.

Parameters

Drupal\node\Node $node: A node entity to modify.

$context: Array of additional information about what triggered the action. Includes the following elements:

  • owner_uid: User ID to assign to the node.

See also

node_assign_owner_action_form()

node_assign_owner_action_validate()

node_assign_owner_action_submit()

Related topics

File

drupal/core/modules/node/node.module, line 3578
The core module that allows content to be submitted to the site.

Code

function node_assign_owner_action(Node $node, $context) {
  $node->uid = $context['owner_uid'];
  $owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(
    ':uid' => $context['owner_uid'],
  ))
    ->fetchField();
  watchdog('action', 'Changed owner of @type %title to uid %name.', array(
    '@type' => node_get_type_label($node),
    '%title' => $node
      ->label(),
    '%name' => $owner_name,
  ));
}