uid.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a user id
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("User: ID"),
  13. // keyword to use for %substitution
  14. 'keyword' => 'user',
  15. 'description' => t('Creates a user context from a user ID argument.'),
  16. 'context' => 'ctools_argument_uid_context',
  17. 'placeholder form' => array(
  18. '#type' => 'textfield',
  19. '#description' => t('Enter the user ID of a user for this argument'),
  20. ),
  21. 'default' => array('to_arg' => TRUE),
  22. 'path placeholder' => '%pm_uid_arg', // This is in pagemanager.
  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. }