Commit bcfd0911 authored by KarenS's avatar KarenS

#107128 - add teaser support via a display overview form - patch by Eaton, dopry,

   yched and me
parent b6619266
......@@ -15,3 +15,17 @@ table.content-field-overview td {
text-align:center;
}
.field .field-label,
.field .field-label-inline,
.field .field-label-inline-first {
font-weight:bold;
}
.field .field-label-inline,
.field .field-label-inline-first {
display:inline;
}
.field .field-label-inline {
visibility:hidden;
}
......@@ -242,3 +242,24 @@ function content_update_8() {
return $ret;
}
/**
* Add display_settings column
*/
function content_update_9() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($ret, 'node_field_instance', 'display_settings', 'text', array('not null' => TRUE, 'default' => ''));
break;
case 'mysql':
case 'mysqli':
// TODO : why not db_add_column ?
$ret[] = update_sql("ALTER TABLE {node_field_instance} ADD COLUMN display_settings mediumtext NOT NULL");
break;
}
return $ret;
}
......@@ -17,6 +17,10 @@ function content_help($section) {
return t('<strong>CCK:</strong> Allows administrators to define new content types.');
}
if (preg_match('!^admin/node/types/.*/display$!', $section)) {
return t("Configure how this content type's fields and field labels should be displayed when it's viewed in teaser and full-page mode.");
}
if (strpos($section, 'node/add') === 0) {
$types = content_types();
foreach ($types as $type_name => $type) {
......@@ -158,6 +162,15 @@ function content_menu($may_cache) {
'access' => $access,
'callback arguments' => array(arg(3)),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
);
$items[] = array(
'path' => 'admin/node/types/'. arg(3) .'/display',
'title' => t('display fields'),
'callback' => 'content_admin_display_overview_form',
'access' => $access,
'callback arguments' => array(arg(3)),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items[] = array(
......@@ -167,7 +180,7 @@ function content_menu($may_cache) {
'access' => $access,
'callback arguments' => array(arg(3)),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'weight' => 3,
);
if (arg(4) == 'fields' && arg(5)
......@@ -343,8 +356,9 @@ function content_view(&$node, $teaser = FALSE, $page = FALSE) {
if ($node->in_preview) {
_content_widget_invoke('process form values', $node);
}
$node->body = implode('', _content_field_invoke('view', $node, FALSE, $page));
$node->teaser = implode('', _content_field_invoke('view', $node, TRUE, $page));
$node->body = implode('', _content_field_view($node, FALSE, $page));
$node->teaser = implode('', _content_field_view($node, TRUE, $page));
$node->readmore = (strlen($node->teaser) < strlen($node->body));
}
......@@ -586,6 +600,42 @@ function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL
return $return;
}
/**
* Format field output based on display settings.
*/
function _content_field_view($node, $teaser = NULL, $page = NULL) {
$type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
$type = content_types($type_name);
$field_types = _content_field_types();
$context = $teaser ? 'teaser' : 'full';
$return = array();
if (count($type['fields'])) {
foreach ($type['fields'] as $field) {
$node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();
$formatter = isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default';
$value = '';
if ($formatter != 'hidden') {
$module = $field_types[$field['type']]['module'];
$callbacks = module_invoke($module, 'field_settings', 'callbacks', $field);
if (isset($callbacks['view']) && $callbacks['view']) {
$value = module_invoke($module, 'field', 'view', $node, $field, $node_field, $teaser, $page);
}
if (empty($value)) {
foreach ($node_field as $delta => $item) {
$items[$delta]['view'] = content_format($field, $item, $formatter, $node);
}
$value = theme('field', $node, $field, $items, $teaser, $page);
}
}
$return[$field['field_name']] = $value;
}
}
return $return;
}
/**
* Invoke a widget hook.
*/
......@@ -757,7 +807,7 @@ function _content_type_info($reset = FALSE) {
$type_result = db_query('SELECT * FROM {node_type_content} nt ORDER BY nt.type_name ASC');
while ($type = db_fetch_array($type_result)) {
$type['fields'] = array();
$field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type_name']);
$field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.display_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type_name']);
while ($field = db_fetch_array($field_result)) {
// Overwrite global field information with specific information
$field = array_merge($info['fields'][$field['field_name']], $field);
......@@ -774,6 +824,7 @@ function _content_type_info($reset = FALSE) {
$field['widget']['description'] = $field['description'];
unset($field['description']);
$field['type_name'] = $type['type_name'];
$field['display_settings'] = $field['display_settings'] ? unserialize($field['display_settings']) : array();
$type['fields'][$field['field_name']] = $field;
}
......@@ -922,16 +973,31 @@ function content_format($field, $item, $formatter = 'default', $node = NULL) {
* An HTML string containing the fully themed field.
*/
function theme_field(&$node, &$field, &$items, $teaser, $page) {
if (isset($field['display_settings']['label']['format'])) {
$label = $field['display_settings']['label']['format'] ? $field['display_settings']['label']['format'] : 'header';
}
else {
$label = '';
}
$items_output = '';
foreach ($items as $item) {
foreach ($items as $delta => $item) {
if (!empty($item['view']) || $item['view'] === "0") {
$items_output .= '<div class="field-item">'. $item['view'] .'</div>';
$items_output .= '<div class="field-item">';
if ($label == 'inline') {
$items_output .= '<div class="field-label-inline'. ($delta ? '' : '-first') .'">';
$items_output .= $field['widget']['label'] .':</div> ' ;
}
$items_output .= $item['view'] .'</div>';
}
}
$output = '';
if (!empty($items_output)) {
$output .= '<div class="field field-type-'. strtr($field['type'], '_', '-') .' field-'. strtr($field['field_name'], '_', '-') .'">';
$output .= '<h3 class="field-label">'. $field['widget']['label'] .'</h3>';
if ($label == 'above') {
$output .= '<div class="field-label">'. $field['widget']['label'] .':</div>';
}
$output .= '<div class="field-items">'. $items_output .'</div>';
$output .= '</div>';
}
......
......@@ -527,6 +527,110 @@ function content_admin_field_overview_form_submit($form_id, $form_values) {
}
/**
* Menu callback; presents a listing of fields display settings for a content type.
*
* Form includes form widgets to select which fields appear for teaser, full node...
* and how the field labels should be rendered
*/
function content_admin_display_overview_form($type_name) {
$type = content_types($type_name);
$field_types = _content_field_types();
$form = array();
if (empty($type['fields'])) {
drupal_set_message(t('There are no fields configured for this content type.'));
return $form;
}
$form['#tree'] = TRUE;
foreach ($type['fields'] as $field) {
$form['fields'][$field['field_name']] = _content_admin_display_overview_row($field, $field_types[$field['type']]);
}
$form['type_name'] = array('#type' => 'hidden', '#value' => $type['type_name']);
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return drupal_get_form('content_admin_display_overview_form', $form);
}
function theme_content_admin_display_overview_form($form) {
$header = array(t('Field'), t('Type'), t('Label'));
foreach (_content_admin_display_contexts() as $key => $title) {
$header[] = $title;
}
$rows = array();
foreach (element_children($form['fields']) as $field) {
$row = array();
foreach (element_children($form['fields'][$field]) as $key) {
$row[] = form_render($form['fields'][$field][$key]);
}
$rows[] = $row;
}
$output = theme('table', $header, $rows, array('class' => 'content-field-display-overview'));
$output .= form_render($form);
return $output;
}
function content_admin_display_overview_form_submit($form_id, $form_values) {
$type = $form_values['type_name'];
foreach ($form_values['fields'] as $fieldname => $fieldvalues) {
$display_settings = array();
foreach ($fieldvalues as $key => $value) {
$display_settings[$key] = $value;
}
db_query("UPDATE {node_field_instance} SET display_settings = '%s' WHERE type_name = '%s' AND field_name = '%s'",
serialize($display_settings), $form_values['type_name'], $fieldname);
}
drupal_set_message(t('Updated display settings.'));
content_clear_type_cache();
}
function _content_admin_display_overview_row($field, $field_type) {
$defaults = $field['display_settings'];
$options = array();
foreach ($field_type['formatters'] as $name => $formatter_info) {
$options[$name] = $formatter_info['label'];
}
$options['hidden'] = t('<Hidden>');
$label_options = array(
'above' => t('Above'),
'inline' => t('Inline'),
'hidden' => t('<Hidden>'),
);
$row = array();
$row['type_label'] = array('#value' => $field['widget']['label']);
$row['type'] = array('#value' => $field_type['label']);
$row['label']['format'] = array(
'#type' => 'select',
'#options' => $label_options,
'#default_value' => isset($defaults['label']['format']) ? $defaults['label']['format'] : 'above',
);
foreach (_content_admin_display_contexts() as $key => $title) {
$row[$key]['format'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : 'default',
);
}
return $row;
}
function _content_admin_display_contexts() {
return array(
'teaser' => t('Teaser'),
'full' => t('Full'),
);
}
/**
* Menu callback; presents the form for adding a new field.
*/
......
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