Commit 704345a2 authored by merlinofchaos's avatar merlinofchaos
Browse files

Improved field overriding + theme wizard support!

parent 6cc942f6
......@@ -720,9 +720,12 @@ function views_theme_field() {
$args = func_get_args();
$function = array_shift($args);
$field_name = array_shift($args);
$view = array_pop($args);
if (!($func = theme_get_function($function . "_" . $field_name))) {
$func = theme_get_function($function);
if (!($func = theme_get_function($function . '_' . $view->name . '_' . $field_name))) {
if (!($func = theme_get_function($function . '_' . $field_name))) {
$func = theme_get_function($function);
}
}
if ($func) {
......@@ -1250,17 +1253,6 @@ function views_view_add_sort(&$view, $table, $field, $order, $option) {
// ---------------------------------------------------------------------------
// Themeable and support for themeables.
/**
* Figure out how to display the data of a field. Many fields simply display
* the data as-is, but many fields have to massage that data, which is
* done through handlers.
*
* DEPRECATED. Left in for backward compatibility.
*/
function _views_handle_field($fields, $field, $data) {
return views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $data);
}
/**
* Themeable function to handle displaying a specific field.
*/
......@@ -1419,7 +1411,7 @@ function theme_views_view_list($view, $nodes, $type) {
if ($field['label']) {
$item .= "<div class='view-label view-label-$field[queryname]'>" . $field['label'] . "</div>";
}
$item .= "<div class='view-field view-data-$field[queryname]'>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node) . "</div>";
$item .= "<div class='view-field view-data-$field[queryname]'>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) . "</div>";
}
}
$items[] = "<div class='view-item view-item-$view->name'>$item</div>\n"; // l($node->title, "node/$node->nid");
......@@ -1439,7 +1431,7 @@ function theme_views_view_table($view, $nodes, $type) {
$row = array();
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
$cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node);
$cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
$cell['class'] = "view-field view-field-$field[queryname]";
$row[] = $cell;
}
......
......@@ -65,6 +65,12 @@ function views_theme_wizard_page() {
'#weight' => 10,
);
$form['submit2'] = array(
'#type' => 'button',
'#value' => t('List Theme Fields'),
'#weight' => 10,
);
$form['#after_build'] = array(
'views_theme_wizard_generate',
);
......@@ -76,20 +82,66 @@ function views_theme_wizard_generate($form, $form_values) {
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['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['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;
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 function phptemplate_views_handle_field_{$view->name}_$field[queryname](\$fields, \$field, \$data)\n\n";
}
return $output;
}
function views_theme_wizard_example_field($view) {
$fieldname = 'phptemplate_views_handle_field_' . $view->field[0]['queryname'];
$output = <<<EOT
/**
* Function to handle a sample field.
*/
function $fieldname(\$fields, \$field, \$data) {
\$info = \$fields[\$field['fullname']];
if (\$field['handler'] && function_exists(\$field['handler'])) {
return \$field['handler'](\$info, \$field, \$data->\$field['queryname'], \$data);
}
if (\$info['handler'] && is_string(\$info['handler']) && function_exists(\$info['handler'])) {
return \$info['handler'](\$info, \$field, \$data->\$field['queryname'], \$data);
}
return check_plain(\$data->\$field['queryname']);
}
EOT;
return $output;
}
function views_theme_wizard_generate_list_code($view) {
$now = format_date(time());
$code = <<<EOT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment