Index: views_theme_wizard.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/views_theme_wizard.module,v retrieving revision 1.13 diff -u -p -r1.13 views_theme_wizard.module --- views_theme_wizard.module 7 Dec 2006 06:25:50 -0000 1.13 +++ views_theme_wizard.module 7 Jan 2007 08:53:53 -0000 @@ -33,89 +33,202 @@ function views_theme_wizard_page() { return drupal_get_form('views_theme_wizard_form', $views); } -function views_theme_wizard_form($views) { + +function views_theme_wizard_form($views, $form_values = array()) { + $form = array(); + + if (!isset($form_values['step'])) { + $step = 1; + } + else { + $step = $form_values['step']; + } + $form['markup'] = array( '#value' => t('
The views theming wizard generates code that you can use in your phptemplate theme to help you customize the output of a view. Simply select a theme and it will generate code for your template.php as well as template files for the individual views.
At this time this code assumes your view is a list type view! It may not generate effective code for other types of views. Future versions of this program will be smarter, and give more options, but this wizard is still a huge start.
'), '#weight' => 0, ); - - $form['vid'] = array( - '#type' => 'select', - '#options' => $views, - '#title' => t('Select a view'), - '#weight' => 5, - ); - - $form['code1'] = array( - '#type' => 'markup', - '#value' => '', - ); - - $form['code2'] = array( - '#type' => 'markup', - '#value' => '', - ); - $form['code3'] = array( - '#type' => 'markup', - '#value' => '', - ); - - - $form['submit'] = array( - '#type' => 'button', - '#value' => t('Generate Theme'), - '#weight' => 10, - ); - - $form['submit2'] = array( - '#type' => 'button', - '#value' => t('List Theme Fields'), - '#weight' => 10, - ); - - $form['#after_build'] = array( - 'views_theme_wizard_generate', - ); + $op = isset($form_values['op']) ? $form_values['op'] : ''; + + while ($step != 0) { + if (1 == $step) { + $form['step'] = array( + '#type' => 'hidden', + '#value' => $step, + ); + $form['vid'] = array( + '#type' => 'select', + '#options' => $views, + '#title' => t('Select a view'), + '#weight' => 5, + ); + $form['theme_type'] = array( + '#type' => 'select', + '#title' => t('Select Theme Type'), + '#options' => views_theme_wizard_get_theme_types(), + '#weight' => 6, + ); + $form['submit'] = array( + '#type' => 'button', + '#value' => t('Select Theme Type'), + '#weight' => 10, + ); + $form['submit2'] = array( + '#type' => 'button', + '#value' => t('List Theme Fields'), + '#weight' => 11, + ); + $form['step'] = array( + '#type' => 'hidden', + '#value' => $step + 1, + ); + + $step = 0; + } + elseif (2 == $step && $op == t('List Theme Fields')) { + $view = views_get_view($form_values['vid']); + $form['code1']['#type'] = 'textarea'; + $form['code1']['#value'] = views_theme_wizard_list_fields($view); + $form['code1']['#title'] = t('This is a list of all the theme functions you can use to override individual field displays'); + $form['code1']['#rows'] = 20; + + $form['code2']['#type'] = 'textarea'; + $form['code2']['#value'] = views_theme_wizard_example_field($view); + $form['code2']['#title'] = t('This is a basic theme function', array('%s' => $view->name)); + $form['code2']['#rows'] = 20; + + $step = 0; + } + elseif (2 == $step && $op = t('Select Theme Type')) { + $view = views_get_view($form_values['vid']); + $type = $form_values['theme_type']; + $additions = module_invoke_all('views_theme_wizard_types', 'configure', $type, $view); + if (! $additions) { + $step = 3; + continue; + } + $form['theme_type'] = array( + '#type' => 'hidden', + '#value' => $type, + ); + $form['vid'] = array( + '#type' => 'hidden', + '#value' => $form_values['vid'], + ); + foreach ($additions as $k => $v) { + $form[$k] = $v; + } + $form['generate'] = array( + '#type' => 'button', + '#value' => t('Generate Theme'), + '#weight' => 10, + ); + $form['step'] = array( + '#type' => 'hidden', + '#value' => $step + 1, + ); + + $step = 0; + + } + elseif (3 == $step) { + $view = views_get_view($form_values['vid']); + $form['code1']['#type'] = 'textarea'; + $form['code1']['#value'] = views_theme_wizard_generate_list_code($form_values['theme_type'], $view, $form_values); + $form['code1']['#title'] = t('This code goes in your template.php file'); + $form['code1']['#rows'] = 20; + + $form['code2']['#type'] = 'textarea'; + $form['code2']['#value'] = views_theme_wizard_generate_list_template_code($view); + $form['code2']['#title'] = t('This code goes in a file named views-list-%s.tpl.php', array('%s' => $view->name)); + $form['code2']['#rows'] = 20; + + $form['code3']['#type'] = 'textarea'; + $form['code3']['#value'] = views_theme_wizard_generate_list_stylesheet_code($view); + $form['code3']['#title'] = t('This code goes in a file named views-list-%s.css', array('%s' => $view->name)); + $form['code3']['#rows'] = 20; + + $step = 0; + } + + } + + $form['#multistep'] = TRUE; + $form['#redirect'] = FALSE; + return $form; } -function views_theme_wizard_generate($form, $form_values) { - $view = views_get_view($form_values['vid']); - if (!$view) { - return $form; - } - $op = $_POST['op']; - if ($op == t('Generate Theme')) { - $form['code1']['#type'] = 'textarea'; - $form['code1']['#value'] = views_theme_wizard_generate_list_code($view); - $form['code1']['#title'] = t('This code goes in your template.php file'); - $form['code1']['#rows'] = 20; - - $form['code2']['#type'] = 'textarea'; - $form['code2']['#value'] = views_theme_wizard_generate_list_template_code($view); - $form['code2']['#title'] = t('This code goes in a file named views-list-%s.tpl.php', array('%s' => $view->name)); - $form['code2']['#rows'] = 20; - - $form['code3']['#type'] = 'textarea'; - $form['code3']['#value'] = views_theme_wizard_generate_list_stylesheet_code($view); - $form['code3']['#title'] = t('This code goes in a file named views-list-%s.css', array('%s' => $view->name)); - $form['code3']['#rows'] = 20; - } - - if ($op == t('List Theme Fields')) { - $form['code1']['#type'] = 'textarea'; - $form['code1']['#value'] = views_theme_wizard_list_fields($view); - $form['code1']['#title'] = t('This is a list of all the theme functions you can use to override individual field displays'); - $form['code1']['#rows'] = 20; - - $form['code2']['#type'] = 'textarea'; - $form['code2']['#value'] = views_theme_wizard_example_field($view); - $form['code2']['#title'] = t('This is a basic theme function', array('%s' => $view->name)); - $form['code2']['#rows'] = 20; - +function views_theme_wizard_get_theme_types() { + $types = module_invoke_all('views_theme_wizard_types', 'list'); + ksort($types); + return $types; +} + + +function views_theme_wizard_views_theme_wizard_types($op='list', $delta='', $view=NULL, $options = array()) { + + switch($op) { + case 'list': + if ('list' == $op) { + return array( + 'straight' => t('Straight List'), + 'grouped' => t('Grouped List'), + 'tree' => t('Nested Tree'), + ); + } + case 'configure': + switch ($delta) { + case 'straight': + break; + case 'grouped': + $options = array(); + foreach ($view->field as $field) { + $options[$field['queryname']] = $field['label'] ? $field['label'] : $field['queryname']; + } + $form['group_field'] = array( + '#type' => 'select', + '#title' => t('Select the field on which to group'), + '#options' => $options, + ); + $form['test'] = array('#type'=>'markup'); + return $form; + break; + case 'tree': + $options = array(); + foreach ($view->field as $field) { + $options[$field['queryname']] = $field['label'] ? $field['label'] : $field['queryname']; + } + $form['tree_key_field'] = array( + '#type' => 'select', + '#title' => t('Select the field to use as the ID for each row (usually nid)'), + '#options' => $options, + ); + $form['tree_reference_field'] = array( + '#type' => 'select', + '#title' => t('Select the field that refers to the parent node by the ID field'), + '#options' => $options, + ); + return $form; + break; + } + break; + case 'code': + switch ($delta) { + case 'straight': + return views_theme_wizard_type_generate_code_straight($view); + break; + case 'grouped': + return views_theme_wizard_type_generate_code_grouped($view, $options); + break; + case 'tree': + return views_theme_wizard_type_generate_code_tree($view, $options); + break; + } + break; } - return $form; + } function views_theme_wizard_list_fields($view) { @@ -156,9 +269,10 @@ EOT; return $output; } -function views_theme_wizard_generate_list_code($view) { +function views_theme_wizard_generate_list_code($theme_type, $view, $options) { $now = format_date(time()); - $code = <<