1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Plugin to provide an relationship handler for term from node.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
10 |
|
|
* by the system that includes this file.
|
11 |
|
|
*/
|
12 |
|
|
$plugin = array(
|
13 |
|
|
'title' => t('User category edit form from user'),
|
14 |
|
|
'keyword' => 'user_category_form',
|
15 |
|
|
'description' => t('Adds user category edit form from a user context.'),
|
16 |
|
|
'required context' => new ctools_context_required(t('User'), 'user'),
|
17 |
|
|
'context' => 'ctools_user_category_edit_form_from_user_context',
|
18 |
08475715
|
Assos Assos
|
'edit form' => 'ctools_user_category_edit_form_from_user_settings_form',
|
19 |
|
|
'defaults' => array('category' => NULL),
|
20 |
85ad3d82
|
Assos Assos
|
);
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* Return a new context based on an existing context.
|
24 |
|
|
*/
|
25 |
|
|
function ctools_user_category_edit_form_from_user_context($context, $conf) {
|
26 |
|
|
if (empty($context->data)) {
|
27 |
|
|
return ctools_context_create_empty('user_edit_form', NULL);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
08475715
|
Assos Assos
|
if(!empty($conf['category'])) {
|
31 |
|
|
return ctools_context_create('user_edit_form', $context->data, array('category' => $conf['category']));
|
32 |
|
|
}
|
33 |
|
|
|
34 |
85ad3d82
|
Assos Assos
|
if (isset($context->data->user_category)) {
|
35 |
|
|
return ctools_context_create('user_edit_form', $context->data, array('category' => $context->data->user_category));
|
36 |
|
|
}
|
37 |
08475715
|
Assos Assos
|
|
38 |
|
|
return ctools_context_create('user_edit_form', $context->data);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
|
|
* Settings form for the relationship.
|
43 |
|
|
*/
|
44 |
|
|
function ctools_user_category_edit_form_from_user_settings_form($form, &$form_state) {
|
45 |
|
|
$conf = $form_state['conf'];
|
46 |
|
|
|
47 |
|
|
$categories = _user_categories();
|
48 |
|
|
$options = array();
|
49 |
|
|
foreach($categories as $category) {
|
50 |
|
|
$options[$category['name']] = $category['title'];
|
51 |
|
|
}
|
52 |
|
|
$form['category'] = array(
|
53 |
|
|
'#type' => 'select',
|
54 |
|
|
'#title' => t('Category'),
|
55 |
|
|
'#options' => $options,
|
56 |
|
|
'#default_value' => isset($conf['category']) ? $conf['category'] : NULL,
|
57 |
|
|
'#empty_option' => 'Default',
|
58 |
|
|
);
|
59 |
|
|
|
60 |
|
|
return $form;
|
61 |
85ad3d82
|
Assos Assos
|
} |