user_from_node.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide an relationship handler for node from user.
  5. */
  6. /**
  7. * Plugins are described by creating a $plugin array which will be used
  8. * by the system that includes this file.
  9. */
  10. $plugin = array(
  11. 'title' => t('Node author'),
  12. 'keyword' => 'user',
  13. 'description' => t('Creates the author of a node as a user context.'),
  14. 'required context' => new ctools_context_required(t('Node'), 'node'),
  15. 'context' => 'ctools_user_from_node_context',
  16. 'no ui' => TRUE,
  17. );
  18. /**
  19. * Return a new context based on an existing context.
  20. */
  21. function ctools_user_from_node_context($context, $conf) {
  22. // If unset it wants a generic, unfilled context, which is just NULL.
  23. if (empty($context->data) || !isset($context->data->uid)) {
  24. return ctools_context_create_empty('user', NULL);
  25. }
  26. if (isset($context->data->uid)) {
  27. // Load the user that is the author of the node.
  28. $uid = $context->data->uid;
  29. $account = user_load($uid);
  30. // Send it to ctools.
  31. return ctools_context_create('user', $account);
  32. }
  33. }