From fd538897d0abfe840ca9c17bffc23a7cc91aa420 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 18 Mar 2022 08:57:19 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#1542 --- wire/core/Fieldgroups.php | 3 ++- wire/core/Templates.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wire/core/Fieldgroups.php b/wire/core/Fieldgroups.php index de5ce983..f37872d6 100644 --- a/wire/core/Fieldgroups.php +++ b/wire/core/Fieldgroups.php @@ -9,7 +9,8 @@ * * ProcessWire 3.x, Copyright 2022 by Ryan Cramer * https://processwire.com - * + * + * @method Fieldgroup clone(Saveable $item, $name = '') * @method int saveContext(Fieldgroup $fieldgroup) * @method array getExportData(Fieldgroup $fieldgroup) * @method array setImportData(Fieldgroup $fieldgroup, array $data) diff --git a/wire/core/Templates.php b/wire/core/Templates.php index 2b4dfc4b..2647e746 100644 --- a/wire/core/Templates.php +++ b/wire/core/Templates.php @@ -380,7 +380,7 @@ class Templates extends WireSaveableItems { if($fieldgroup->name == $item->name) { // if the fieldgroup and the item have the same name, we'll also clone the fieldgroup - $fieldgroup = $this->wire('fieldgroups')->clone($fieldgroup, $name); + $fieldgroup = $this->wire()->fieldgroups->clone($fieldgroup, $name); $item->fieldgroup = $fieldgroup; } @@ -388,10 +388,13 @@ class Templates extends WireSaveableItems { if($item && $item->id && !$item->altFilename) { // now that we have a clone, lets also clone the template file, if it exists - $path = $this->wire('config')->paths->templates; - $file = $path . $item->name . '.' . $this->wire('config')->templateExtension; - if($original->filenameExists() && is_writable($path) && !file_exists($file)) { - if(copy($original->filename, $file)) $item->filename = $file; + $config = $this->wire()->config; + $files = $this->wire()->files; + $path = $config->paths->templates; + $ext = $config->templateExtension ? $config->templateExtension : 'php'; + $file = "$path$item->name.$ext"; + if($original->filenameExists() && is_writable($path) && !$files->exists($file)) { + if($files->copy($original->filename, $file)) $item->filename = $file; } }