uid.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide an argument handler for a user id.
  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("User: ID"),
  12. // Keyword to use for %substitution.
  13. 'keyword' => 'user',
  14. 'description' => t('Creates a user context from a user ID argument.'),
  15. 'context' => 'ctools_argument_uid_context',
  16. 'placeholder form' => array(
  17. '#type' => 'textfield',
  18. '#description' => t('Enter the user ID of a user for this argument'),
  19. ),
  20. 'default' => array('to_arg' => TRUE),
  21. // This is in pagemanager.
  22. 'path placeholder' => '%pm_uid_arg',
  23. 'path placeholder to_arg' => TRUE,
  24. 'no ui' => TRUE,
  25. );
  26. /**
  27. * Discover if this argument gives us the user we crave.
  28. */
  29. function ctools_argument_uid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  30. // If unset it wants a generic, unfilled context.
  31. if ($empty) {
  32. return ctools_context_create_empty('user');
  33. }
  34. // We can accept either a node object or a pure nid.
  35. if (is_object($arg)) {
  36. return ctools_context_create('user', $arg);
  37. }
  38. if (!is_numeric($arg)) {
  39. return NULL;
  40. }
  41. $account = user_load($arg);
  42. if (!$account) {
  43. return NULL;
  44. }
  45. return ctools_context_create('user', $account);
  46. }