Synopsis

Content Type Clone allows Drupal users with the "Administer content types" permission
to clone content types in one click.

Access the content type list, click on "clone" for the content type you want to clone, save the clone form. The module will then clone the content type, and copy all fields to the newly created clone.

Content Type Clone also offers the options to:

* Copy all nodes from the source content type to the target content type
* Delete nodes from the source content type after they have been copied to the target clone

Content Type Clone has been created in order to offer a quick and simple way to clone content types and automatically copy all fields in Drupal.

Git command

git clone --branch 7.x-1.x https://git.drupal.org/sandbox/davidfiaty/2745827.git content_type_clone

Sandbox project page

Content Type Clone

  • Token: when this module is enabled, tokens are available to create a name, a machine name
    and a description for cloned content types.

These modules will also allow you to clone a content type:

However, none of them provide the following complementary maintenance tasks when cloning a content type:

* Copy all nodes from the source content type to the target content type
* Delete nodes from the source content type after they have been copied to the target clone
* Use tokens to compose the name and description of the generated clones

Content Type Clone is also extremely simple to use: click on the clone link in the content types list page.

Manual reviews of other projects

https://www.drupal.org/node/2744549#comment-11293341
https://www.drupal.org/node/2746485#comment-11293049
https://www.drupal.org/node/2746815#comment-11293245

CommentFileSizeAuthor
#17 cloneerror.png35.53 KBsumit.prajapati
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David Fiaty created an issue. See original summary.

PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpsgitdrupalorgsandboxdavidfiaty2745827git

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

PA robot’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

I'm a robot and this is an automated message from Project Applications Scraper.

David Fiaty’s picture

Status: Closed (won't fix) » Needs review

Fixed pareview.sh issues and user reported errors at https://www.drupal.org/node/2794499 and https://www.drupal.org/node/2807077.

David Fiaty’s picture

Issue summary: View changes

Updated the module description text.

klausi’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

Review of the 7.x-1.x branch (commit 7811160):

  • Coder Sniffer has found some issues with your code (please check the Drupal coding standards).
    
    FILE: /home/klausi/pareview_temp/content_type_clone.module
    --------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------
     28 | ERROR | [x] Equals sign not aligned correctly; expected 1 space but
        |       |     found 2 spaces
    --------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------
    
  • No automated test cases were found, did you consider writing Simpletests or PHPUnit tests? This is not a requirement but encouraged for professional software development.

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

manual review:

  1. content_type_clone_create(): this will not scale if there are many nodes in a content type. The node_load_mulitple() will run into a timeout. Only load a limited number of nodes at once instead.
  2. content_type_clone_copy_node(): why do you need to sleep() here? It only makes the process slower? Please explain the reason int he comment, what visibility? That the batch progresses slower?
  3. "$context['message'] = t('Cloning node') . ' ' . $source_node->title;": never concatenate variables to translatable strings, use placeholders with t() instead. See https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7.x . Not sure if this message is later displayed as is in HTML - this could also be an XSS vulnerability. This should be fixed in any case and is currently an application blocker, you need to understand how to use t() correctly. Please check all your t() calls with variables.
  4. content_type_clone_create_form(): doc block is wrong, this is not hook_form(). See https://www.drupal.org/docs/develop/coding-standards/api-documentation-a... . Same for content_type_clone_create_form_validate().
  5. Your module file is quite long. Can you split up the page and form callbacks into a dedicated *.admin.inc file?
  6. content_type_clone_create_form_submit(): Why do you define $function here? Just call the function directly?
  7. content_type_clone_preprocess_html(): don't add your CSS in a global HTML preprocess hook, add it with #attached on the render array of you page/form callback. See https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...

Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

David Fiaty’s picture

Thank you for your review klausi. All reported issues have been fixed, including the pareview.sh one. 2 comments on the points you listed above:
1. content_type_clone_create():
The node_load_mulitple() task has been moved to the batch operations and replaced by a node_load() call. I hope this will address the performance concerns.

2. content_type_clone_copy_node():
The sleep() function was used for test matters and should have been removed indeed.
I will be awaiting for another review, hoping to be granted permission to promote full projects!
Thanks a lot.

David Fiaty’s picture

The review bonus system says that in order to benefit from it again I have to review 3 more project applications, which I will do very happily.

But what happens when/if I review a project that has already been reviewed multiple times?
If I haven't found any issue in the project, can I still review it and say everything looks ok for me?

The underlying question is: will my review count for the review bonus system even though it doesn't report any issue?

David Fiaty’s picture

Status: Needs work » Needs review
VoidE’s picture

Review of the 7.x-1.x branch:

I found only 1 performance issue:
In content_type_clone_preprocess_html, you are calling the arg-funtion three times. Maybe it's better to use:

$args = arg();
if ($args[0] == 'admin' && $args[2] == 'clone' && $args[3] == 'create') {
...
}

This way, you're calling one time the arg-function instead of three times. Just a small thing to think of.

You also added the CSS via attached to in content_type_clone_create_form(), but didn't delete the preprocess_html function.

Beside above, this module looks good to me!

VoidE’s picture

Status: Needs review » Needs work
David Fiaty’s picture

Thank you for this review VoidE. Issues fixed.

David Fiaty’s picture

Status: Needs work » Needs review
sjpagan’s picture

Status: Needs review » Reviewed & tested by the community

I tested this module, a great module, works very well ...

David Fiaty’s picture

Thank you very much for your review sjpagan. I'm looking forward to seeing the module officially published!

sjpagan’s picture

:-)

sumit.prajapati’s picture

FileSize
35.53 KB

Hi David,

I am trying to cloning content type but getting some error. Please refer below image.

David Fiaty’s picture

Hi Sumit, thanks for the feedback.
Your issue seems to be server related. See here: https://www.drupal.org/node/1108688

jeetendrakumar’s picture

Module is working fine form me.

Suggestion
1. Once cloning is complete page should be redirect to content type list page.

deepanker_bhalla’s picture

Hi,

I used your module and found it really great as it saves time.

But when I cloned my content type(Eg: gallery) then only the body gets cloned in manage fields as well as in manage display. My all the custom fields didn't get clone.

Thus look into this.

David Fiaty’s picture

Hi deepanker_bhalla, thank you for the report. Unfortunately I can't reproduce your issue. Have you checked your logs? Any information coming from there would be very useful.

Also, could you please provide more information about the content type you're trying to clone? You could maybe use Bundle Copy, export the content type and post it here so that I can install it and see what is going on. Otherwise I'm not sure I could fix your specific issue with only the elements above.

sumit.prajapati’s picture

Hi David,

you can just install fresh drupal and install this module and take any (basic or article) content type clone. issue will be reproduce.
Try it

deepanker_bhalla’s picture

Status: Reviewed & tested by the community » Needs work

Hi David,

As per Sumit(#22) you reproduce the issue...

I just checked my logs and there was a warning coming from your module:

"Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'content_type_clone_set_target_field' not found or invalid function name in _batch_process() (line 284 of /var/www/html/drupald/drupal/includes/batch.inc)."

You can try on any of the content types whether it's custom or not.

David Fiaty’s picture

Hi guys, thank you for the feedback. I wasn't expecting this but it looks like a regression from the code sjpagan has tested. Looking at your log, there is obviously a function missing. I'll post an updated version soon. Thanks a lot for your time.

David Fiaty’s picture

Following the comments by deepanker_bhalla and Sumit Prajapati:
After having moved the content_type_clone_set_target_field to a clone.admin.inc file, the batch operation needed the said file to be specified in order to find the function. Adding one line to the batch operations array fixed the issue:

'file' => drupal_get_path('module', 'content_type_clone') . '/includes/clone.admin.inc',

The function can now be found by the batch and the issue is gone. This also addresses comment #19 by jeetendrakumar.
Thank you very much for your help and for testing the module.

David Fiaty’s picture

Status: Needs work » Needs review
deepanker_bhalla’s picture

Status: Needs review » Reviewed & tested by the community

Working fine now. Great work...

David Fiaty’s picture

Thank you! Hopefully the D8 version will come out soon. What's the next step after RTBC?

Ankush_03’s picture

HI David,

Below is my manual review :
1. use l() function on line 'No content types available. Add content type.',

David Fiaty’s picture

Hi agautam, thank you for the feedback.
You have probably noticed that the function you're talking about is a reimplementation of a Drupal core function hook_node_overview_types(). I didn't see any issue with the way it is now because it's core Drupal code.

I might be wrong but as far as I know, the use of l() is not compulsory, just useful if you want to add complementary attributes and classes to your links.
I don't mind changing it if someone can confirm I should, but I don't want to make unnecessary changes either if the current code is fine.

The code in question from D7 core currently looks like this:

<?php
 $build['node_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t(
      'No content types available. <a href="@link">Add content type</a>.',
      array(
        '@link' => url('admin/structure/types/add'),
      )
    ),
  );
?>

Is it required to replace the a tag by l()?

sumit.prajapati’s picture

Hi David,

Now its working.

David Fiaty’s picture

great news, thanks for your time.

apaderno’s picture

Assigned: Unassigned » apaderno
Status: Reviewed & tested by the community » Fixed

Thank you for your contribution!

I updated your account so you can opt into security advisory coverage now.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thank you, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks go the dedicated reviewer(s) as well.

apaderno’s picture

David Fiaty’s picture

Hi kiamlaluno, thank you for your message. I will go through all recommended readings. I am not sure about what I should be doing now.
Are you expecting some action from me, or am I just supposed to wait? Is this the official approval of my project?

deepanker_bhalla’s picture

Hi David Fiaty,

As per Kiamlaluno, it is approved and now you can promote your sandbox project to Full Project as globally.

David Fiaty’s picture

Great! Thank you very much. Have a good day.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.