Duplicate field settings when creating a new one
Started by vknt, Oct 09 2011 04:03 PM
5 replies to this topic
#1
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..
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..
#3
Posted 10 October 2011 - 09:39 AM
+1 ;D
@somartist | modules created | support me, flattr my work flattr.com
#4
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:
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:
You can of course go back and rename it to whatever you want.
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:
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); 0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













