6 * Callback function to supply a list of content types.
8 function panels_profile_fields_panels_content_types() {
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
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',
26 * 'Render' callback for the 'profile fields' content type.
28 function panels_profile_fields_content($subtype, $conf, $panel_args, $context) {
29 $account = isset($context->data
) ?
drupal_clone($context->data
) : NULL
;
30 $block = new
stdClass();
31 $block->module
= 'profile fields';
34 // Get the category from the options
35 $category = str_replace("_", " ", $conf['category']);
37 // Set the subject to the name of the category
38 $block->subject
= $category;
40 // Put all the fields in the category into an array
41 profile_view_profile($account);
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'];
52 if (count($vars) == 0) {
53 // Output the given empty text
54 $output = $conf['empty'];
57 // Call the theme function with the field vars
58 $output = theme('profile_fields_pane', $category, $vars);
61 $block->content
= $output;
62 $block->delta
= $account->uid
;
65 $block->subject
= $conf['category'];
66 $block->content
= t('Profile content goes here.');
67 $block->delta
= 'unknown';
74 * Return all content types available.
76 function panels_profile_fields_content_type() {
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),
90 * Helper function : build the list of categories for the 'edit' form.
92 function _panels_profile_fields_options() {
95 $categories = profile_categories();
96 foreach ($categories as
$key => $value) {
97 $cat_list[str_replace(" ", "_", $value['name'])] = $value['title'];
104 * 'Edit' callback for the 'profile fields' content type.
106 function panels_profile_fields_configure($id, $parents, $conf = array()) {
109 $conf = array('title' => '', 'category' => '', 'empty' => '');
112 $form['category'] = array(
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>',
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.'),
126 '#default_value' => $conf['empty'],
127 '#prefix' => '<div class="clear-block no-float">',
128 '#suffix' => '</div>',
135 * 'Title' callback for the 'profile fields' content type.
137 function panels_profile_fields_configure_title($subtype, $conf, $context) {
138 return t('"@s" profile fields', array('@s' => $conf['category']));