user_name.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a username
  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: name"),
  13. // keyword to use for %substitution
  14. 'keyword' => 'user',
  15. 'description' => t('Creates a user context from a user name.'),
  16. 'context' => 'ctools_argument_user_name_context',
  17. 'placeholder form' => array(
  18. '#type' => 'textfield',
  19. '#description' => t('Enter the username of a user for this argument'),
  20. ),
  21. );
  22. /**
  23. * Discover if this argument gives us the user we crave.
  24. */
  25. function ctools_argument_user_name_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  26. // If unset it wants a generic, unfilled context.
  27. if ($empty) {
  28. return ctools_context_create_empty('user');
  29. }
  30. // We can accept either a node object or a pure nid.
  31. if (is_object($arg)) {
  32. return ctools_context_create('user', $arg);
  33. }
  34. $account = user_load_by_name($arg);
  35. if (!$account) {
  36. return NULL;
  37. }
  38. return ctools_context_create('user', $account);
  39. }