user_name.inc 1.1 KB

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