Hi,

I've attached a patch which makes the title modification an optional setting. It defaults to on, so it won't change any existing installations. If you disable the title modification, instead a message is set with a link to the original node.

It's pretty simple, and will make a big difference for my users who keep forgetting to remove the Clone of (the titles aren't supposed to be modified).

Enjoy!
--Andrew

Comments

pwolanin’s picture

looks reasonable, but please roll against 6.x (HEAD) first.

deviantintegral’s picture

Version: 5.x-2.x-dev » 6.x-1.x-dev
StatusFileSize
new2.31 KB

Here is a version rolled against HEAD.

--Andrew

drewish’s picture

it'd be kind of cool if the text was a variable so you could do something like "!title - cloned" or "FIXED: !title".

update: you could of course set it to "!title" and achieve the goal of this issue.

deviantintegral’s picture

How about using the token module? I'd like to avoid introducing another method of tokens. It should be simple to make token not required, but used if available. Though making token required might be simpler.

boris mann’s picture

+1 for this feature. I think it should work like this:

If token module is not installed, then it might be as simple as an on / off checkbox for pre-pending this text. There is a note next to this setting that says "install token module for advanced settings".

If token module IS installed, then "advanced behaviour" is turned on, and you have a text field to enter in tokens.

psynaptic’s picture

StatusFileSize
new1.69 KB

I created this patch before I saw this issue. My patch is much simpler so much more chance of it being committed.

I have to delete the "Clone of " text for each node I clone and I clone about 1-200 nodes per project! I'm really hoping this will get committed.

psynaptic’s picture

Another feature I would like is the ability to increment any numeric value found in the title.

My use case is:

1. Create node with a title such as "Event Title 1".
2. Clone the node and the title ends up as "Event Title 2".

This would save me a lot of time.

It would also be great to be able to clone a node multiple times using this increment.

pwolanin’s picture

#6 is certainly CNW, since the t() call is useless as written

psynaptic’s picture

I'd be happy to do anything I can. Could you outline what the problem is?

pwolanin’s picture

As written the call to t() does nothing except pass through to strtr().

Also, you can already localize this to just '!title', so it is optional already.

psynaptic’s picture

So what is the solution?

robloach’s picture

Status: Needs review » Closed (works as designed)

Automatic Node Titles will do this and that's what is being used on http://drupalbin.com .

drewish’s picture

Rob Loach, it's not clear to me how to use Automatic Node Titles to only set the title on cloned nodes. Could you elaborate a bit?

psynaptic’s picture

Status: Closed (works as designed) » Needs review

I can't figure out how to achieve this using ANT either.

I have used that module a lot for specific node types but I don't think it's applicable here.

robloach’s picture

To make the "Clone Of" node titles optional like you see on http://drupalbin.com , do the following:

  1. Install Clone Node module
  2. Make a node type clonable
  3. Install Automatic Node Titles module
  4. Edit the node type at admin/content/node-type/%nodetype% and use "Automatically generate the title if the title field is left empty". DrupalBin uses "[type-name]" for the replacement pattern

Hope that helps! Or am I accomplishing something different here?

psynaptic’s picture

What you describe *could* work but I don't think it would be very smooth. It means you have to set it up, then turn it on and off each time you want to switch between being able to clone a node type and revert to normal behaviour.

The solution I provided a patch for works but I agree it's not great. I though pwolanin might have the answer to the bad use of t() so I could learn and refactor.

robloach’s picture

OH! You're saying customize the "Clone of" prefix text? Sorry, I didn't interpret it correctly. To do this on DrupalBin, I used String Overrides and stuck "Clone of !title" in as an override. In this case I changed it to "Fix for !title". I would love for this to be part of Clone Node core though.

Thanks!

psynaptic’s picture

Hehe, np. :)

I hope this or a similar fix gets committed. I don't mind patching the module each time but would be easier for everyone to have the option built-in.

robloach’s picture

Status: Needs review » Needs work

Again, you don't have to patch the module. Just use String Overrides ;-) .

As for this going into Clone Node modules itself, I don't think it should be regarded as just a prefix because what if you wanted to make it "!title: Cloned Version" or something? I think it should rather be called "Title Pattern", or something along those lines, and provide replacement patterns like !title, like how the User Settings page does it. Having this replacement pattern though, removes the ability for internationalism. Translations don't work on dynamic text since the variables table isn't translated. Hmmmmmmmm............

psynaptic’s picture

bah.

robloach’s picture

Status: Needs work » Needs review
? node_clone-cloned_node_title_prefix.patch
Index: clone.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_clone/clone.pages.inc,v
retrieving revision 1.3
diff -u -p -r1.3 clone.pages.inc
--- clone.pages.inc	7 May 2008 02:28:58 -0000	1.3
+++ clone.pages.inc	27 May 2009 15:00:13 -0000
@@ -1,6 +1,6 @@
 <?php
 // $Id: clone.pages.inc,v 1.3 2008/05/07 02:28:58 pwolanin Exp $
-// $Name:  $
+// $Name: HEAD $
 
 /**
  * Menu callback to configure module settings.
@@ -24,7 +24,13 @@ function clone_settings() {
     '#options' => array(t('Require confirmation (recommended)'), t('Bypass confirmation')),
     '#description' => t('A new node may be saved immediately upon clicking the "clone" tab when viewing a node, bypassing the normal confirmation form.'),
   );
-  
+  $form['basic']['clone_format'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Node title format'),
+    '#description' => t('Enter the formatting for the node title.'),
+    '#default_value' => variable_get('clone_format', 'Clone of !title'),
+  );
+
   $form['publishing'] = array(
     '#type' => 'fieldset',
     '#title' => t('Should the publishing options ( e.g. published, promoted, etc) be reset to the defaults?'),
@@ -123,7 +129,7 @@ function clone_node_prepopulate($origina
       }
       $node->path = NULL;
       $node->files = array();
-      $node->title = t('Clone of !title', array('!title' => $node->title));
+      $node->title = t(variable_get('clone_format', 'Clone of !title'), array('!title' => $node->title));
       drupal_set_title(check_plain($node->title));
 
       if (variable_get('clone_reset_'. $node->type, FALSE)) {

How about this? It's still kind of translatable because it's passed through t().

pwolanin’s picture

@Rob Loach - doesn't that still violate the principle of not passing dynamic text through t()?

robloach’s picture

Yeah, probably. I just can't think of another way around it.... Tokens?

pwolanin’s picture

I'd be fine with using toekn module as long as the default is still to localize this.

E.g. the user could save to the variable anything suitable for standard node token replacement if token module is available. Thus, if the variable is non-empty the token replacement is done, otherwise it localizes it as it does now.

inforeto’s picture

+1 for doing it within the module instead of relying on other modules.
Some sites do not use locale for performance or other purposes.

pwolanin’s picture

Status: Needs review » Needs work
benkewell’s picture

+2 for doing it within the module instead of relying on other modules.
it is more straight forward to allow setting this within the module.
i believe it'll be better to allow customizing the prefix (and maybe also add suffix?) used in the cloned node title
by setting the prefix to empty by user, it allows cloning an exact copy of node including the title,
which is something i need on my website.

AlexisWilke’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB

pwolanin,

I suggest you check this in or write the token version so we have a version that actually works. Now I don't foresee much use in having the token module functionality when all you do is change one token. And how does the token module help with translations?

Thank you Rob.
Alexis Wilke

AlexisWilke’s picture

StatusFileSize
new2.08 KB

There is a better version that includes all the "Clone of ..." titles.

Note that patch gives us an improvement that we don't have otherwise. Another way to write the patch, which would actually be cleaner, would be to call a function and that function would take care of computing the new title. That way it would be done in one single place. Thus, to make changes later, it would be easier since you'd already have everything in one place.

Thank you.
Alexis Wilke

cybermache’s picture

I just use Token, CCK and Automatic Node Titles modules.
In my clone-able nodes I've created another Title text field with a name that has some reference to the node type, such as field_page_title. I then set the Automatic Node title of that content type to 'Automatically generate the title and hide the title field' and in the 'Pattern for the title' field I enter the [field_page_title_formatted] plus any other token values that I want. I don't have to change any of my views since the original title is always populated with the newly entered title.

Just thought others might find this helpful. If this could be condensed to the Clone module settings and then maybe controllable per content type it would be preferred.

wxman’s picture

Just wanted to add that this was a help to me and my new site. The patch worked perfectly.

danepowell’s picture

Title: Make 'Clone Of' title optional » Make 'Clone of...' text configurable
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.37 KB

I'd like to see this as well. I think #29 should be committed, and if separate issues need to be created to add Token support or translation support, then so be it. Here's #29 just re-rolled Git-style against HEAD.

mikeytown2’s picture

#32 works!

jhubley’s picture

I used #32 as well and it's great. I'd also like to see this committed.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

The value of a variable is in some way user input and should not be passed through t()

wonder95’s picture

So would it be better to pass them through check_plain()?

mikeytown2’s picture

Given what we want to do, I think running variable_get(...) through check_plain() is the best option. This isn't a HUGE issue as someone needs the permissions to set a variable in order to XSS exploit this; but it's still an issue.

  t(check_plain(variable_get('clone_format', 'Clone of !title')), array('!title' => $node->title));
AlexisWilke’s picture

Since this title would be editable in the node (if I remember properly) then the level of format available to the user editing the node needs to be applied (i.e. the format of the body.) Since it's more complicated to do that, a check_plain() is a fairly good fallback. The regular title gets check_plain() applied to it so it certainly would make sense. The filter_xss() would be another solution which keeps a few tags if we wanted to support some HTML and it is still safe.

Thank you.
Alexis Wilke

thedavidmeister’s picture

@psynaptic in #7, if you want to do something more specialised like that you might be better off leveraging the hook provided by node clone to get the exact sequence you want in the titles

Is it so difficult to use module_exists to see if token is available and leverage it if it does?

The idea of using autonodetitles is good, but as pointed out you can't have a different pattern for clones as normal nodes so wouldn't it be an idea to model/integrate the solution here with what was done in the module there?

thedavidmeister’s picture

incidentally, it is worth pointing out that the basic token API is part of core in D7 so the overhead of introducing this as a dependancy should be relatively minor.

thedavidmeister’s picture

also, patch #32 could be improved by moving the logic that returns a new title from an original node object into its own function and calling that from the cloning functions. That would make any future changes we wanted to make to the title substitutions easier to maintain.

thedavidmeister’s picture

StatusFileSize
new5.98 KB

Here's a new patch that builds on the patch in #32, rolled against 6.x-1.x dev

What I've done here:

* Token integration - First checks if token module is enabled and leverages it if it is, !title is equated to [title-raw] for nodes
* I felt that using the same replacement pattern for menu links as node titles for a cloned node was an over-simplification and actually just wrong for most use-cases, so I added an extra text-field that can be used to customise the cloned menu links' title. This also integrates optionally with Token but !title is still replaced using the t() function in the same way that it alway has
* Minor UI improvements, separating replacement patterns into their own formfield on the settings page
* Separating the title generation logic into two new functions to make future maintenance patches and integrations with other modules easier
* In response to the concerns raised in #35, the title generation function runs everything through check_plain() and the check_plain() function that was always in the prepopulate function has been removed as it is now redundant.

It all works for me, but as always don't take my word for it! test it out on your own site and leave feedback so we can get this to RTBC and hopefully committed :)

thedavidmeister’s picture

Status: Needs work » Needs review
thedavidmeister’s picture

Status: Needs review » Needs work

just had a thought... for proper token integration you would want to be able to take tokens from both the new node and the original node. If you're running things through hook_clone_node_alter then values might be different for each.

this still needs work

jenlampton’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

bumping to 7.x because I'm guessing new features are not still going into the 6.x branch at this point :)

thedavidmeister’s picture

wow. I have no recollection of doing this...

lunk rat’s picture

Title: Make 'Clone of...' text configurable » Add config option for default title behavior
Issue summary: View changes

Would still be a great addition to this module's feature set in 7.x

igorik’s picture

is there a working patch with any of d7 version? thanks

neena.thakur’s picture

I did it with jQuery
if(window.location.href.indexOf("clone") > -1) {
clongString = $(".node-form #edit-title").val();
clongString = clongString.replace("Clone of ",'');
$(".node-form #edit-title").val(clongString);
}

sense-design’s picture

StatusFileSize
new2.54 KB

Here is a new patch which adds a configuration option to allow the prefix or not, patch made for D7