user_links.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Plugins are described by creating a $plugin array which will be used
  4. * by the system that includes this file.
  5. */
  6. $plugin = array(
  7. 'single' => TRUE,
  8. 'title' => t('User links'),
  9. 'icon' => 'icon_user.png',
  10. 'description' => t('User links of the referenced user.'),
  11. 'required context' => new ctools_context_required(t('User'), 'user'),
  12. 'category' => t('User'),
  13. 'defaults' => array(
  14. 'override_title' => FALSE,
  15. 'override_title_text' => '',
  16. 'build_mode' => '',
  17. ),
  18. );
  19. /**
  20. * Output function for the user links.
  21. */
  22. function ctools_user_links_content_type_render($subtype, $conf, $panel_args, $context) {
  23. if (!empty($context) && empty($context->data)) {
  24. return;
  25. }
  26. $account = clone $context->data;
  27. $block = new stdClass();
  28. $block->module = 'user';
  29. $block->delta = $account->uid;
  30. if (empty($account)) {
  31. $block->delta = 'placeholder';
  32. $block->subject = t('User name.');
  33. $block->content = t('User links go here.');
  34. }
  35. else {
  36. $block->subject = $account->name;
  37. user_build_content($account, $conf['build_mode']);
  38. if (!empty($account->content['links'])) {
  39. $block->content = $account->content['links'];
  40. }
  41. else {
  42. $block->content = '';
  43. }
  44. }
  45. return $block;
  46. }
  47. /**
  48. * Returns an edit form for the custom type.
  49. */
  50. function ctools_user_links_content_type_edit_form($form, &$form_state) {
  51. $conf = $form_state['conf'];
  52. $entity = entity_get_info('user');
  53. $build_mode_options = array();
  54. foreach ($entity['view modes'] as $mode => $option) {
  55. $build_mode_options[$mode] = $option['label'];
  56. }
  57. $form['build_mode'] = array(
  58. '#title' => t('Build mode'),
  59. '#type' => 'select',
  60. '#description' => t('Select a build mode for this user.'),
  61. '#options' => $build_mode_options,
  62. '#default_value' => $conf['build_mode'],
  63. );
  64. return $form;
  65. }
  66. function ctools_user_links_content_type_edit_form_submit($form, &$form_state) {
  67. // Copy everything from our defaults.
  68. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  69. $form_state['conf'][$key] = $form_state['values'][$key];
  70. }
  71. }
  72. function ctools_user_links_content_type_admin_title($subtype, $conf, $context) {
  73. return t('"@s" links', array('@s' => $context->identifier));
  74. }