'admin/views/wizard', 'access' => user_access('administer views'), 'title' => t('theme wizard'), 'callback' => 'views_theme_wizard_page', 'type' => MENU_LOCAL_TASK, ); } return $items; } function views_theme_wizard_page() { $result = db_query("SELECT name, description FROM {view_view}"); $views = array(); while ($view = db_fetch_object($result)) { $views[$view->name] = $view->name . ': ' . $view->description; } $default_views = _views_get_default_views(); $views_status = variable_get('views_defaults', array()); foreach ($default_views as $view) { if (!$views[$view->name] && ($views_status[$view->name] == 'enabled' || (!$views_status[$view->name] && !$view->disabled))) { $views[$view->name] = check_plain($view->name . ': ' . $view->description); } } $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', ); return drupal_get_form('views_theme_wizard_form', $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 your style.css'); $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; } return $form; } function views_theme_wizard_list_fields($view) { $fields = _views_get_fields(); $output = "These functions will override the given fields for just this view:\n\n"; foreach ($view->field as $field) { $fieldinfo = $fields[$field['id']]; $output .= "$fieldinfo[name]\n phptemplate_views_handle_field_{$view->name}_$field[queryname]\n\n"; } $output .= "\n\nThese functions will override the given fields for every view:\n\n"; foreach ($view->field as $field) { $fieldinfo = $fields[$field['id']]; $output .= "$fieldinfo[name]\n phptemplate_views_handle_field_$field[queryname]\n\n"; } return $output; } function views_theme_wizard_example_field($view) { $fieldname = 'phptemplate_views_handle_field_' . $view->name . '_' . $view->field[0]['queryname']; $output = <<