diff --git a/clone.module b/clone.module
index b4ce7c2..ebc9d1d 100644
--- a/clone.module
+++ b/clone.module
@@ -1,4 +1,5 @@
'clone.pages.inc',
'description' => 'Allows users to clone (copy then edit) an existing node.',
);
+ if (!module_exists('node_clone_tab')) {
+ $config = config('clone.settings');
+ if ($config->get('clone_link') == 'tab') {
+ $type = MENU_LOCAL_TASK;
+ } else {
+ $type = MENU_LOCAL_ACTION;
+ }
+ } else {
+ $type = MENU_LOCAL_ACTION;
+ }
+ $item['type'] = MENU_LOCAL_TASK;
$items['node/%node/clone/%clone_token'] = array(
'access callback' => 'clone_access_cloning',
'access arguments' => array(1, TRUE, 3),
@@ -57,7 +69,7 @@ function clone_menu() {
'title arguments' => array(1),
'weight' => 5,
'file' => 'clone.pages.inc',
- 'type' => MENU_LOCAL_ACTION,
+ 'type' => $type,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
return $items;
@@ -151,8 +163,8 @@ function clone_node_type_update($info) {
}
/**
- * Implements hook_views_api.
- */
+ * Implements hook_views_api.
+ */
function clone_views_api() {
return array(
'api' => 3,
@@ -193,8 +205,7 @@ function clone_form_node_form_alter(&$form, $form_state, $form_id) {
function clone_form_node_admin_content_alter(&$form, $form_state, $form_id) {
if (config_get('clone.settings', 'clone_method') == 'prepopulate') {
$destination = backdrop_get_destination();
- }
- else {
+ } else {
$destination = array();
}
// The property attribute changes in the $form array depending on the user role.
@@ -258,7 +269,7 @@ function clone_action_clone($original_node, $context) {
$node = _clone_node_prepare($original_node, $prefix_title);
if (isset($val['substitute_from']) && strlen($val['substitute_from']) && isset($val['substitute_to'])) {
$i = (!empty($val['substitute_case_insensitive']) ? 'i' : '');
- $pattern = '#'. strtr($val['substitute_from'], array('#' => '\#')) . '#' . $i;
+ $pattern = '#' . strtr($val['substitute_from'], array('#' => '\#')) . '#' . $i;
foreach (array('title') as $property) {
$new = preg_replace($pattern, $val['substitute_to'], $node->{$property});
if ($new) {
@@ -266,7 +277,7 @@ function clone_action_clone($original_node, $context) {
}
}
foreach (array('body') as $property) {
- foreach($node->{$property} as $lang => $row) {
+ foreach ($node->{$property} as $lang => $row) {
foreach ($row as $delta => $data) {
foreach (array('value', 'summary') as $key) {
if (isset($node->{$property}[$lang][$delta][$key])) {
@@ -287,8 +298,7 @@ function clone_action_clone($original_node, $context) {
if (module_exists('rules')) {
rules_invoke_event('clone_node', $node, $original_node);
}
- }
- else {
+ } else {
backdrop_set_message(t('Clone failed for %title : not permitted for nodes of type %type', array('%title' => $original_node->title, '%type' => $original_node->type)), 'warning');
}
}
@@ -297,28 +307,28 @@ function clone_action_clone($original_node, $context) {
* Action form.
*/
function clone_action_clone_form($context) {
- $form['clone_context'] = array(
- '#tree' => TRUE,
- );
- $form['clone_context']['prefix_title'] = array(
+ $form['clone_context'] = array(
+ '#tree' => TRUE,
+ );
+ $form['clone_context']['prefix_title'] = array(
'#title' => t('Prefix title'),
'#type' => 'checkbox',
'#description' => t('Should cloned node tiles be prefixed?'),
'#default_value' => isset($context['clone_context']['prefix_title']) ? $context['clone_context']['prefix_title'] : 1,
);
- $form['clone_context']['substitute_from'] = array(
+ $form['clone_context']['substitute_from'] = array(
'#title' => t('Substitute from string'),
'#type' => 'textfield',
'#description' => t('String (or regex) to substitute from in title and body.'),
'#default_value' => isset($context['clone_context']['substitue_from']) ? $context['clone_context']['substitue_from'] : '',
);
- $form['clone_context']['substitute_to'] = array(
+ $form['clone_context']['substitute_to'] = array(
'#title' => t('Substitute to string'),
'#type' => 'textfield',
'#description' => t('String (or regex) to substitute to in title and body.'),
'#default_value' => isset($context['clone_context']['substitue_to']) ? $context['clone_context']['substitue_to'] : '',
);
- $form['clone_context']['substitute_case_insensitive'] = array(
+ $form['clone_context']['substitute_case_insensitive'] = array(
'#title' => t('Case insensitive substitution'),
'#type' => 'checkbox',
'#description' => t('Should the substituion match be case insensitive?'),
diff --git a/clone.pages.inc b/clone.pages.inc
index fd127f8..30e7944 100644
--- a/clone.pages.inc
+++ b/clone.pages.inc
@@ -8,6 +8,9 @@
* Menu callback to configure module settings.
*/
function clone_settings($form, &$form_state) {
+ if (module_exists('node_clone_tab')) {
+ backdrop_set_message(t('Node Clone module already implements clone link as tab. You can disable Node Clone Tab module and set the link as tab in this form. Otherwise, Node Clone Tab will take over Node Clone.'), 'error');
+ }
$config = config('clone.settings');
$form['#config'] = 'clone.settings';
@@ -41,18 +44,31 @@ function clone_settings($form, &$form_state) {
'#default_value' => (int) $config->get('clone_menu_links'),
'#description' => t('Should any menu link for a node also be cloned?'),
);
- $form['basic']['clone_use_node_type_name'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use node type name in clone link'),
- '#default_value' => (int) $config->get('clone_use_node_type_name'),
- '#description' => t('If checked, the link to clone the node will contain the node type name, for example, "Clone this article", otherwise it will read "Clone content".'),
- );
+
$form['basic']['clone_prefix_title'] = array(
'#type' => 'checkbox',
+ '#prefix' => '',
'#title' => t('Prefix title'),
'#default_value' => (bool) $config->get('clone_prefix_title'),
'#description' => t('Should cloned node titles be prefixed?'),
);
+ if (!module_exists('node_clone_tab')) {
+ $form['basic']['clone_link'] = array(
+ '#type' => 'radios',
+ '#title' => t('How to show the clone link'),
+ '#options' => array('link' => t('As action link under tabs'), 'tab' => t('As tab')),
+ '#default_value' => $config->get('clone_link'),
+ );
+ }
+
+ $form['basic']['clone_use_node_type_name'] = array(
+ '#type' => 'checkbox',
+ '#prefix' => '',
+ '#title' => t('Use node type name in clone link'),
+ '#default_value' => (int) $config->get('clone_use_node_type_name'),
+ '#description' => t('If checked, the link to clone the node will contain the node type name, for example, "Clone this article", otherwise it will read "Clone content".'),
+ );
+
$form['publishing'] = array(
'#type' => 'fieldset',
@@ -81,9 +97,30 @@ function clone_settings($form, &$form_state) {
'#description' => t('Select any node types which should never be cloned. In other words, all node types where cloning will fail.'),
);
+ $form['#submit'][] = 'node_clone_settings_submit';
+
return system_settings_form($form);
}
+/**
+ * Custom submit handler for node_clone settings.
+ */
+function node_clone_settings_submit($form, &$form_state) {
+
+ // Clear all caches including the menu cache.
+ cache_flush('menu');
+ // Schedule the menu rebuild to happen at the end of the request.
+ backdrop_register_shutdown_function('node_clone_delayed_menu_rebuild');
+
+}
+
+/**
+ * Function to rebuild the menu during shutdown.
+ */
+function node_clone_delayed_menu_rebuild() {
+ menu_rebuild();
+}
+
/**
* Menu callback: prompt the user to confirm the operation
*/
diff --git a/config/clone.settings.json b/config/clone.settings.json
index f8f0436..cf72d2c 100755
--- a/config/clone.settings.json
+++ b/config/clone.settings.json
@@ -4,5 +4,6 @@
"clone_omitted": [],
"clone_nodes_without_confirm": 0,
"clone_use_node_type_name": 0,
- "clone_menu_links": 0
+ "clone_menu_links": 0,
+ "clone_link": "link"
}