From 8acf76adf516614472b54bdeb749891ddd60acb5 Sat, 2 Jul 2016 14:06:43 +0200 From: hass Date: Sat, 2 Jul 2016 14:06:37 +0200 Subject: [PATCH] Issue #1233810 by hass: Customizable revision log message diff --git a/tests/external_node_update.test b/tests/external_node_update.test index 9edbcf8..641116d 100644 --- a/tests/external_node_update.test +++ b/tests/external_node_update.test @@ -29,6 +29,7 @@ 'name' => 'External node update', 'description' => 'Test if nodes are correctly moderated when updated by third party modules.', 'group' => 'Workbench Moderation', + 'dependencies' => array('token'), ); } diff --git a/tests/workbench_moderation.files.test b/tests/workbench_moderation.files.test index 874f2ed..6d50ad2 100644 --- a/tests/workbench_moderation.files.test +++ b/tests/workbench_moderation.files.test @@ -50,6 +50,7 @@ 'name' => 'Workbench Moderation file attachments', 'description' => 'Test moderation on nodes with with file attachments.', 'group' => 'Workbench Moderation', + 'dependencies' => array('token'), ); } diff --git a/tests/workbench_moderation.test b/tests/workbench_moderation.test index 3b692ff..0adcdb4 100644 --- a/tests/workbench_moderation.test +++ b/tests/workbench_moderation.test @@ -50,6 +50,7 @@ 'name' => 'Moderation tab', 'description' => 'Create a moderated node publish it using the "Moderate" tab.', 'group' => 'Workbench Moderation', + 'dependencies' => array('token'), ); } @@ -137,6 +138,7 @@ 'description' => 'Test access to the "Draft" tab and publishing from the mini moderation form on the draft tab.', 'group' => 'Workbench Moderation', 'dependencies' => array( + 'token', 'workbench', // Workbench is required for the mini moderation form ), ); @@ -211,6 +213,7 @@ 'name' => 'Publish from node form', 'description' => 'Publish a moderated node from the node form.', 'group' => 'Workbench Moderation', + 'dependencies' => array('token'), ); } @@ -251,6 +254,7 @@ 'name' => 'Unpublish moderated content', 'description' => 'Create and publish a moderated node, then unpublish using the "Moderate" tab.', 'group' => 'Workbench Moderation', + 'dependencies' => array('token'), ); } @@ -293,6 +297,7 @@ 'description' => 'Test whether the redirect keeps up with a changed alias', 'group' => 'Workbench Moderation', 'dependencies' => array( + 'token', 'workbench', // Workbench is required for the mini moderation form. 'pathauto', // Pathauto is required for automatic aliases, without which this test is unnecessary. ), diff --git a/workbench_moderation.info b/workbench_moderation.info index 3f9939f..d3b0a87 100644 --- a/workbench_moderation.info +++ b/workbench_moderation.info @@ -16,3 +16,6 @@ files[] = tests/external_node_update.test files[] = tests/workbench_moderation.test files[] = tests/workbench_moderation.files.test + +; Required for create/update log messages. +dependencies[] = token diff --git a/workbench_moderation.install b/workbench_moderation.install index 8d68ed3..d02224a 100644 --- a/workbench_moderation.install +++ b/workbench_moderation.install @@ -31,6 +31,8 @@ $types = node_type_get_types(); foreach ($types as $type_object) { $type = $type_object->type; + variable_del("workbench_moderation_default_revision_information_log_create_$type"); + variable_del("workbench_moderation_default_revision_information_log_update_$type"); variable_del("workbench_moderation_default_state_$type"); // Get node options that might hold a moderation flag. diff --git a/workbench_moderation.module b/workbench_moderation.module index 26ea794..39f52f5 100644 --- a/workbench_moderation.module +++ b/workbench_moderation.module @@ -703,7 +703,7 @@ // Don't proceed if moderation is not enabled on this content, or if // we're replacing an already-published revision. - if (!workbench_moderation_node_moderated($node) || + if (!workbench_moderation_node_moderated($node) || !empty($node->workbench_moderation['updating_live_revision'])) { return; } @@ -818,6 +818,31 @@ 'disabled' => array(':input[name="node_options[revision]"]' => array('checked' => FALSE)), ); + // The default "create" moderation note. + $form['workflow']['workbench_moderation_default_revision_information_log_create'] = array( + '#default_value' => variable_get('workbench_moderation_default_revision_information_log_create_' . $form['#node_type']->type, t('Created by [user:name].')), + '#description' => t('Default create revision log message. Can be overridden by the user.'), + '#title' => t('Default create moderation notes'), + '#type' => 'textarea', + '#element_validate' => array('token_element_validate'), + '#token_types' => array('user'), + ); + // The default "update" moderation note. + $form['workflow']['workbench_moderation_default_revision_information_log_update'] = array( + '#default_value' => variable_get('workbench_moderation_default_revision_information_log_update_' . $form['#node_type']->type, t('Edited by [user:name].')), + '#description' => t('Default update revision log message. Can be overridden by the user.'), + '#title' => t('Default update moderation notes'), + '#type' => 'textarea', + '#element_validate' => array('token_element_validate'), + '#token_types' => array('user'), + ); + $form['workflow']['workbench_moderation_default_revision_information_log'] = array( + '#theme' => 'token_tree', + '#token_types' => array('user'), + '#show_restricted' => TRUE, + '#dialog' => TRUE, + ); + // This select element is hidden when moderation is not enabled. $form['workflow']['workbench_moderation_default_state'] = array( '#title' => t('Default moderation state'), @@ -922,13 +947,13 @@ ); // Set a default revision log message. - $logged_name = (user_is_anonymous() ? variable_get('anonymous', t('Anonymous')) : format_username($user)); if (!empty($form['#node']->nid)) { - $form['revision_information']['log']['#default_value'] = t('Edited by !user.', array('!user' => $logged_name)); + $revision_information_log = t(variable_get('workbench_moderation_default_revision_information_log_update_' . $form['#node']->type, t('Edited by [user:name].'))); } else { - $form['revision_information']['log']['#default_value'] = t('Created by !user.', array('!user' => $logged_name)); + $revision_information_log = t(variable_get('workbench_moderation_default_revision_information_log_create_' . $form['#node']->type, t('Created by [user:name].'))); } + $form['revision_information']['log']['#default_value'] = token_replace($revision_information_log, array('user' => $user), array('sanitize' => FALSE, 'clear' => TRUE)); // Move the revision log into the publishing options to make things pretty. if ($form['options']['#access']) {