diff --git a/submitted_by.install b/submitted_by.install
index 66b76bc6278bc565efc42474c680a49021025a62..6ac9de742ba4872a9361f146534ce2c2977b3d23 100644
--- a/submitted_by.install
+++ b/submitted_by.install
@@ -15,3 +15,43 @@ function submitted_by_uninstall() {
variable_del('submitted_by_comment_' . $type);
}
}
+
+/**
+ * Convert settings for view modes.
+ */
+function submitted_by_update_7000(&$sandbox) {
+ // Get stuff from entity system.
+ $entity_info = entity_get_info('node');
+ $view_modes = array_keys($entity_info['view modes']);
+
+ // Get all node type names.
+ $types = node_type_get_names();
+
+ // Progress info.
+ $sandbox['max'] = count($types);
+ $sandbox['progress'] = 0;
+
+ // Go through each content type.
+ foreach ($types as $type => $name) {
+ $strings = array();
+ $var = "submitted_by_$type";
+ $current = variable_get($var, NULL);
+
+ // Just in case we didn't finish last time.
+ if (is_string($current)) {
+ // Build a new string array.
+ $strings = array_fill_keys($view_modes, $current);
+
+ // Save the array.
+ variable_set($var, $strings);
+ }
+
+ // Track our progress.
+ $sandbox['progress']++;
+ }
+
+ // Indicate that we're done.
+ $sandbox['#finished'] = 1;
+
+ return t('The Submitted By module is now ready for View modes.');
+}
diff --git a/submitted_by.module b/submitted_by.module
index bcd9d5be559e5c773b4473ba1175809823818d84..76f39ec7c05438f65fe4d4290e062704bf719bd9 100644
--- a/submitted_by.module
+++ b/submitted_by.module
@@ -11,8 +11,13 @@
*/
function submitted_by_form_node_type_form_alter(&$form, &$form_state) {
$type = isset($form['#node_type']->type) ? $form['#node_type']->type : '';
- $current_value = variable_get('submitted_by_' . $type, NULL);
$enabled = variable_get('node_submitted_' . $type, TRUE);
+ $current_value = variable_get('submitted_by_' . $type, array());
+
+ // Just in case the update hasn't run yet.
+ if (!is_array($current_value)) {
+ $current_value = array('full' => $current_value);
+ }
if (isset($form['type'])) {
$form['display']['submitted_by'] = array(
@@ -24,40 +29,76 @@ function submitted_by_form_node_type_form_alter(&$form, &$form_state) {
),
);
- // Note: node module will add "_type" to the variable name.
- $form['display']['submitted_by']['submitted_by'] = array(
- '#type' => 'textfield',
- '#maxlength' => 255,
- '#title' => t("Byline text"),
- '#default_value' => $enabled ? $current_value : NULL,
- '#description' => t("When a node is displayed, text in this box will be used to override the normal byline attribution and date-posted text. Default is \"Submitted by [node:author] on [node:created]\""),
- '#element_validate' => array('token_element_validate'),
- '#token_types' => array('node'),
- );
+ // Get info about view_modes.
+ $entity_info = entity_get_info('node');
+
+ $form['display']['submitted_by']['view_modes'] = array(
+ '#type' => 'value',
+ '#value' => $entity_info['view modes'],
+ );
+
+ foreach ($entity_info['view modes'] as $mode => $info) {
+ // Note: node module will add "_type" to the variable name.
+ $form['display']['submitted_by']["submitted_by_$mode"] = array(
+ '#type' => 'textfield',
+ '#maxlength' => 255,
+ '#title' => t("Byline text - @mode view mode", array('@mode' => $info['label'])),
+ '#default_value' => $enabled ? (isset($current_value[$mode]) ? $current_value[$mode] : '') : NULL,
+ '#description' => t('When a node is displayed in the "@mode" view mode, the text in this box
+ will be used to override the normal byline attribution and date-posted text.
+ Default is "Submitted by [node:author] on [node:created]"', array('@mode' => $info['label'])),
+ '#element_validate' => array('token_element_validate'),
+ '#token_types' => array('node'),
+ );
+ }
+
$form['display']['submitted_by']['token_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node'),
- );
+ );
if (isset($form['comment'])) {
$form['comment']['submitted_by'] = array(
'#type' => 'container',
- );
+ );
$form['comment']['submitted_by']['submitted_by_comment'] = array(
'#type' => 'textfield',
'#maxlength' => 255,
'#title' => t("Byline text"),
'#default_value' => variable_get('submitted_by_comment_' . $type, NULL),
'#description' => t("When a comment is displayed, text in this box will be used to override the normal byline attribution and date-posted text. Default is \"Submitted by [comment:author] on [comment:created]\""),
- '#element_validate' => array('token_element_validate'),
- '#token_types' => array('comment'),
- );
+ '#element_validate' => array('token_element_validate'),
+ '#token_types' => array('comment'),
+ );
$form['comment']['submitted_by']['token_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array('comment'),
- );
+ );
}
+
+ // Provide a submit handler to clean up our variables.
+ if (isset($form['#submit'])) {
+ array_unshift($form['#submit'], 'submitted_by_node_form_submit');
+ }
+ else {
+ $form['#submit'] = array('submitted_by_node_form_submit');
+ }
+ }
+}
+
+/**
+ * Submission handler to aggregate the patterns into an array.
+ */
+function submitted_by_node_form_submit($form, &$form_state) {
+ $strings = array();
+ // Get all the values.
+ foreach ($form_state['values']['view_modes'] as $mode => $info) {
+ $var = "submitted_by_$mode";
+ $strings[$mode] = $form_state['values'][$var];
+ unset($form_state['values'][$var]);
}
+ // Save the settings.
+ variable_set('submitted_by_' . $form_state['values']['type'], $strings);
}
/**
@@ -100,7 +141,7 @@ function submitted_by_node_view($node, $view_mode, $langcode) {
$fields = field_extra_fields_get_display('node', $node->type, $view_mode);
if (isset($fields['submitted_by']['visible']) && $fields['submitted_by']['visible']) {
$node->content['submitted'] =
- array('#markup' => '' . submitted_by_do_replace($node) . '');
+ array('#markup' => '' . submitted_by_do_replace($node, $view_mode) . '');
}
else {
$node->content['submitted'] = array(array());
@@ -109,12 +150,15 @@ function submitted_by_node_view($node, $view_mode, $langcode) {
return;
}
-function submitted_by_do_replace($node) {
- $submitted_by = variable_get('submitted_by_' . $node->type, NULL);
- if ($submitted_by) {
+/**
+ * Helper function to call token_replace().
+ */
+function submitted_by_do_replace($node, $view_mode = '') {
+ $submitted_by = variable_get('submitted_by_' . $node->type, array());
+ if ($submitted_by && !empty($submitted_by[$view_mode])) {
// Get node tokens.
// Note that we do not suppress un-replaced tokens.
- $output = token_replace($submitted_by, array('node' => $node));
+ $output = token_replace($submitted_by[$view_mode], array('node' => $node));
// Get whatever else can be found, like user stuff.
$output = token_replace($output);
@@ -130,7 +174,7 @@ function submitted_by_do_replace($node) {
*/
function submitted_by_process_node(&$variables) {
$node = $variables['node'];
- $variables['submitted'] = submitted_by_do_replace($node);
+ $variables['submitted'] = submitted_by_do_replace($node, $variables['view_mode']);
// Override the regular submitted variable.
if (isset($variables['content']['submitted_by'])) {