mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 11:14:12 +02:00
Fix issue processwire/processwire-issues#1730
Co-authored-by: matjazpotocnik <matjaz.potocnik@um.si>
This commit is contained in:
@@ -1328,6 +1328,32 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
|
|||||||
return parent::___deleteField($field);
|
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()
|
* Default list of file extensions supported by this field, and used as the default by getConfigInputfields()
|
||||||
* method.
|
* method.
|
||||||
|
Reference in New Issue
Block a user