diff --git a/wire/modules/Fieldtype/FieldtypeFile/FieldtypeFile.module b/wire/modules/Fieldtype/FieldtypeFile/FieldtypeFile.module index c7bd05ce..e95294c5 100644 --- a/wire/modules/Fieldtype/FieldtypeFile/FieldtypeFile.module +++ b/wire/modules/Fieldtype/FieldtypeFile/FieldtypeFile.module @@ -1328,6 +1328,32 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt return parent::___deleteField($field); } + /** + * Return a cloned copy of $field + * + * @param Field $field + * @return Field cloned copy + * + */ + public function ___cloneField(Field $field) { + $this->wire()->fields->addHookAfter('cloned', function(HookEvent $e) { + $e->removeHook(null); // run once only + $oldField = $e->arguments(0); /** @var Field $oldField */ + $newField = $e->arguments(1); /** @var Field $newField */ + if(!$newField->type instanceof FieldtypeFile) return; + $templates = $e->wire()->templates; + $oldTpl = $templates->get("field-$oldField|field-x-$oldField"); + if(!$oldTpl) return; // no custom field-* template present + $newTpl = $templates->clone($oldTpl, str_replace("$oldField", "$newField", $oldTpl->name)); + if($newTpl) { + $e->message(sprintf(__('Cloned fields template - %1$s => %2$s'), $oldTpl->name, $newTpl->name)); + } else { + $e->warning(sprintf(__('Error cloning template - %1$s => %2$s'), $oldTpl->name, $newTpl->name)); + } + }); + return parent::___cloneField($field); + } + /** * Default list of file extensions supported by this field, and used as the default by getConfigInputfields() * method.