Mercurial > defr > drupal > scald > scald_dailymotion
comparison scald_dailymotion.admin.inc @ 4:fd5fb845d0bc
Add an auto-import admin screen
author | Franck Deroche <franck@defr.org> |
---|---|
date | Mon, 19 Jul 2010 14:46:20 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:2a63a6e15166 | 4:fd5fb845d0bc |
---|---|
1 <?php | |
2 // $Id$ | |
3 /** | |
4 * @file | |
5 * Provides admin form for DailyMotion's Scald Provider. | |
6 */ | |
7 | |
8 /** | |
9 * Defines the import settings form. | |
10 */ | |
11 function scald_dailymotion_imports_form() { | |
12 $form = array(); | |
13 $imports = variable_get('scald_dailymotion_imports', array()); | |
14 $types = array('user' => t('User'), 'tag' => t('Tag')); | |
15 if (count($imports)) { | |
16 $form['imports'] = array( | |
17 '#type' => 'fieldset', | |
18 '#title' => t('Current imports'), | |
19 '#tree' => TRUE, | |
20 '#theme' => 'scald_dailymotion_imports_table' | |
21 ); | |
22 foreach ($imports as $key => $import) { | |
23 $form['imports'][$key] = array( | |
24 'type' => array( | |
25 '#type' => 'select', | |
26 '#title' => t('Type'), | |
27 '#options' => array('delete' => t('<Delete>')) + $types, | |
28 '#default_value' => $import['type'] | |
29 ), | |
30 'value' => array( | |
31 '#type' => 'textfield', | |
32 '#title' => t('Identifier'), | |
33 '#default_value' => $import['value'] | |
34 ), | |
35 ); | |
36 } | |
37 } | |
38 $form['add'] = array( | |
39 '#type' => 'fieldset', | |
40 '#title' => t('Add import'), | |
41 '#collapsible' => TRUE, | |
42 '#collapsed' => count($imports) | |
43 ); | |
44 $form['add']['type'] = array( | |
45 '#type' => 'select', | |
46 '#title' => t('Type'), | |
47 '#options' => $types, | |
48 ); | |
49 $form['add']['value'] = array( | |
50 '#type' => 'textfield', | |
51 '#title' => t('Identifier'), | |
52 '#description' => t('This field value meaning depends on the Type | |
53 field defined above. For a <em>User</em> import, put the username | |
54 whose videos you\'d loke to import here, for a tag import, use the | |
55 tag name.') | |
56 ); | |
57 $form['add']['submit'] = array( | |
58 '#type' => 'submit', | |
59 '#value' => t('Add this import'), | |
60 '#submit' => array('scald_dailymotion_imports_form_add') | |
61 ); | |
62 | |
63 $form['submit'] = array( | |
64 '#type' => 'submit', | |
65 '#value' => t('Save configuration') | |
66 ); | |
67 return $form; | |
68 } | |
69 | |
70 /** | |
71 * Handles the submission of the form that adds a new import. | |
72 */ | |
73 function scald_dailymotion_imports_form_add($form, &$form_state) { | |
74 $imports = variable_get('scald_dailymotion_imports', array()); | |
75 $values = $form_state['values']; | |
76 $key = $values['type'] . '-' . $values['value']; | |
77 $imports[$key] = array('type' => $values['type'], 'value' => $values['value']); | |
78 variable_set('scald_dailymotion_imports', $imports); | |
79 drupal_set_message(t('Import added')); | |
80 } | |
81 | |
82 /** | |
83 * Handles the submission of the whole form. | |
84 */ | |
85 function scald_dailymotion_imports_form_submit($form, &$form_state) { | |
86 drupal_set_message(t('The configuration options have been saved.')); | |
87 $imports = array(); | |
88 foreach ($form_state['values']['imports'] as $key => $import) { | |
89 if ($import['type'] != 'delete') { | |
90 $imports[$key] = $import; | |
91 } | |
92 } | |
93 variable_set('scald_dailymotion_imports', $imports); | |
94 } | |
95 | |
96 /** | |
97 * Themes the current imports form. | |
98 */ | |
99 function theme_scald_dailymotion_imports_table($form) { | |
100 $headers = array(t('Type'), t('Identifier')); | |
101 $rows = array(); | |
102 foreach (element_children($form) as $key) { | |
103 // Unset per widget titles, they're already in the column title | |
104 $form[$key]['type']['#title'] = $form[$key]['value']['#title'] = ''; | |
105 // Render our row | |
106 $row = array(); | |
107 $row[] = drupal_render($form[$key]['type']); | |
108 $row[] = drupal_render($form[$key]['value']); | |
109 // And add it to the list of table rows. | |
110 $rows[] = $row; | |
111 } | |
112 return theme('table', $headers, $rows); | |
113 } |