user_links.inc 2.2 KB

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