| Commit | Line | Data |
|---|---|---|
| f2e5a0c5 EM |
1 | <?php |
| 2 | // $Id$ | |
| 3 | ||
| 4 | ||
| 5 | /** | |
| 6 | * Callback function to supply a list of content types. | |
| 7 | */ | |
| 8 | function panels_profile_fields_panels_content_types() { | |
| 9 | $items = array(); | |
| 10 | if (module_exists('profile') && !is_null(profile_categories())) { | |
| 11 | $items['profile_fields'] = array( | |
| 12 | 'title' => t('Profile Fields'), | |
| 13 | 'content_types' => 'panels_profile_fields_content_type', | |
| 14 | // only provides a single content type | |
| 15 | 'single' => TRUE, | |
| 16 | 'render callback' => 'panels_profile_fields_content', | |
| 17 | 'add callback' => 'panels_profile_fields_configure', | |
| 18 | 'edit callback' => 'panels_profile_fields_configure', | |
| 19 | 'title callback' => 'panels_profile_fields_configure_title', | |
| 20 | ); | |
| 21 | } | |
| 22 | return $items; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * 'Render' callback for the 'profile fields' content type. | |
| 27 | */ | |
| ca5643af | 28 | function panels_profile_fields_content($subtype, $conf, $panel_args, $context) { |
| f2e5a0c5 EM |
29 | $account = isset($context->data) ? drupal_clone($context->data) : NULL; |
| 30 | $block = new stdClass(); | |
| 31 | $block->module = 'profile fields'; | |
| 32 | ||
| 33 | if ($account) { | |
| 34 | // Get the category from the options | |
| 35 | $category = str_replace("_", " ", $conf['category']); | |
| 36 | ||
| 37 | // Set the subject to the name of the category | |
| 38 | $block->subject = $category; | |
| 39 | ||
| 40 | // Put all the fields in the category into an array | |
| b76f0bd4 SB |
41 | profile_view_profile($account); |
| 42 | ||
| 43 | if (is_array($account->content[$category])) { | |
| 44 | foreach ($account->content[$category] as $field) { | |
| 45 | if (is_array($field['#attributes'])) { | |
| 46 | $vars[$field['#attributes']['class']]['title'] = $field['#title']; | |
| 47 | $vars[$field['#attributes']['class']]['value'] = $field['#value']; | |
| 48 | } | |
| f2e5a0c5 EM |
49 | } |
| 50 | } | |
| 51 | ||
| f3cee7ee | 52 | if (count($vars) == 0) { |
| f2e5a0c5 EM |
53 | // Output the given empty text |
| 54 | $output = $conf['empty']; | |
| 55 | } | |
| 56 | else { | |
| 57 | // Call the theme function with the field vars | |
| 58 | $output = theme('profile_fields_pane', $category, $vars); | |
| 59 | } | |
| 60 | ||
| 61 | $block->content = $output; | |
| 62 | $block->delta = $account->uid; | |
| 63 | } | |
| 64 | else { | |
| 65 | $block->subject = $conf['category']; | |
| 66 | $block->content = t('Profile content goes here.'); | |
| 67 | $block->delta = 'unknown'; | |
| 68 | } | |
| 69 | ||
| 70 | return $block; | |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| f2e5a0c5 EM |
74 | * Return all content types available. |
| 75 | */ | |
| 76 | function panels_profile_fields_content_type() { | |
| 77 | return array( | |
| 78 | 'description' => array( | |
| 79 | 'title' => t('Profile Category'), | |
| 80 | 'icon' => 'icon_user.png', | |
| 81 | 'path' => panels_get_path('content_types/user'), | |
| 82 | 'description' => t('Profile category contents.'), | |
| 83 | 'required context' => new panels_required_context(t('User'), 'user'), | |
| 84 | 'category' => array(t('User context'), -9), | |
| 85 | ), | |
| 86 | ); | |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Helper function : build the list of categories for the 'edit' form. | |
| 91 | */ | |
| 92 | function _panels_profile_fields_options() { | |
| 93 | $cat_list = array(); | |
| 94 | ||
| 95 | $categories = profile_categories(); | |
| 96 | foreach ($categories as $key => $value) { | |
| 97 | $cat_list[str_replace(" ", "_", $value['name'])] = $value['title']; | |
| 98 | } | |
| 99 | ||
| 100 | return $cat_list; | |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * 'Edit' callback for the 'profile fields' content type. | |
| 105 | */ | |
| 106 | function panels_profile_fields_configure($id, $parents, $conf = array()) { | |
| 107 | // Apply defaults | |
| 108 | if (empty($conf)) { | |
| 109 | $conf = array('title' => '', 'category' => '', 'empty' => ''); | |
| 110 | } | |
| 111 | ||
| 112 | $form['category'] = array( | |
| 113 | '#type' => 'radios', | |
| 114 | '#title' => t('Which category'), | |
| 115 | '#options' => _panels_profile_fields_options(), | |
| 116 | '#default_value' => $conf['category'], | |
| 117 | '#prefix' => '<div class="clear-block no-float">', | |
| 118 | '#suffix' => '</div>', | |
| 119 | ); | |
| 120 | ||
| 121 | $form['empty'] = array( | |
| 122 | '#type' => 'textarea', | |
| 123 | '#title' => 'Empty text', | |
| 124 | '#description' => t('Text to display if category has no data. Note that title will not display unless overridden.'), | |
| 125 | '#rows' => 5, | |
| 126 | '#default_value' => $conf['empty'], | |
| 127 | '#prefix' => '<div class="clear-block no-float">', | |
| 128 | '#suffix' => '</div>', | |
| 129 | ); | |
| 130 | ||
| 131 | return $form; | |
| 132 | } | |
| 133 | ||
| 134 | /** | |
| 135 | * 'Title' callback for the 'profile fields' content type. | |
| 136 | */ | |
| b76f0bd4 | 137 | function panels_profile_fields_configure_title($subtype, $conf, $context) { |
| f2e5a0c5 EM |
138 | return t('"@s" profile fields', array('@s' => $conf['category'])); |
| 139 | } | |
| 140 |