Jump to content


Photo

Duplicate field settings when creating a new one


  • Please log in to reply
5 replies to this topic

#1 vknt

vknt

    Full Member

  • Members
  • PipPipPip
  • 72 posts
  • 9

Posted 09 October 2011 - 04:03 PM

Hi all,

When making a new template you can tell it to duplicate fields from another template. Can we do the same for fields? I spend alot of time configuring fields that are just a 1 setting different than another one I already have

e.g. I love the description on fields. It really helps if I can type something in there to tell what the field does. But e.g. images on 1 page is doing something else on another page. That makes i have to create 2 with only a different description. That is why a duplicate would be useful for me among other things..

#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3114

  • LocationAtlanta, GA

Posted 10 October 2011 - 09:31 AM

It's a good idea and I've had the same need–will plan to add this (likely in 2.2).

[edit: fixed my typing, I'm  terrible at trying to reply using the iphone]

#3 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 10 October 2011 - 09:39 AM

+1  ;D

@somartist | modules created | support me, flattr my work flattr.com


#4 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3114

  • LocationAtlanta, GA

Posted 07 December 2011 - 11:00 AM

This has been added in the latest commit of the 'dev' branch (for 2.2). You'll see the Field duplicate/clone option under the 'advanced' menu when editing a field. From there, you just check the box asking you if you want to clone the field and click save.

You can also access it from the API like this:

<?php
$field = $fields->get('title'); 
$clone = $fields->clone($field); 

The new field that is returned ($clone) has already been saved, so you don't need to save it again.

Also note that it automatically assigns a new name to the field to ensure it's unique. Like with cloned pages, it adds an incrementing number to the end of the name:

<?php
$clone = $fields->clone($field);
echo $field->name; // would print 'title';
echo $clone->name; // would print 'title_1';

You can of course go back and rename it to whatever you want.

<?php
$clone->name = 'something_else';
$clone->save();

Template duplicate/clone

An identical clone() function was also added to the template editor. You'll see it in the 'advanced' menu when editing any Template. When you clone a template, the Fieldgroup is cloned and the template-file is also cloned if /site/templates/ is writable.

Using it in the API is exactly the same as with cloning a field, and the behavior is exactly the same:

<?php
$template = $templates->get('basic-page'); 
$clone = $templates->clone($template);



#5 diogo

diogo

    Hero Member

  • Moderators
  • 1,995 posts
  • 1072

  • LocationPorto, Portugal

Posted 07 December 2011 - 02:20 PM

great :)

#6 vknt

vknt

    Full Member

  • Members
  • PipPipPip
  • 72 posts
  • 9

Posted 07 December 2011 - 02:48 PM

Great stuff!  :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users