mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 11:14:12 +02:00
Fix issue processwire/processwire-issues#1816 by adding support for cloning fieldgroup/field context settings in Fieldgroups class
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
* #pw-body For full details on all methods available in a Fieldgroup, be sure to also see the `WireArray` class.
|
* #pw-body For full details on all methods available in a Fieldgroup, be sure to also see the `WireArray` class.
|
||||||
* #pw-var $fieldgroups
|
* #pw-var $fieldgroups
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method Fieldgroup clone(Saveable $item, $name = '')
|
* @method Fieldgroup clone(Saveable $item, $name = '')
|
||||||
@@ -349,19 +349,46 @@ class Fieldgroups extends WireSaveableItemsLookup {
|
|||||||
*
|
*
|
||||||
* @param Saveable $item Item to clone
|
* @param Saveable $item Item to clone
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool|Saveable $item Returns the new clone on success, or false on failure
|
* @return Fieldgroup|false $item Returns the new clone on success, or false on failure
|
||||||
* @return Saveable|Fieldgroup
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function ___clone(Saveable $item, $name = '') {
|
public function ___clone(Saveable $item, $name = '') {
|
||||||
return parent::___clone($item, $name);
|
if(!$item instanceof Fieldgroup) return false;
|
||||||
// @TODO clone the field context data
|
|
||||||
/*
|
$database = $this->wire()->database;
|
||||||
$id = $item->id;
|
|
||||||
$item = parent::___clone($item);
|
/** @var Fieldgroup|false $fieldgroup */
|
||||||
if(!$item) return false;
|
$fieldgroup = parent::___clone($item, $name);
|
||||||
return $item;
|
if(!$fieldgroup) return false;
|
||||||
*/
|
|
||||||
|
$sql =
|
||||||
|
'SELECT fields_id, sort, data FROM fieldgroups_fields ' .
|
||||||
|
'WHERE fieldgroups_id=:fieldgroups_id ' .
|
||||||
|
'AND data IS NOT NULL';
|
||||||
|
|
||||||
|
$query = $this->wire()->database->prepare($sql);
|
||||||
|
$query->bindValue(':fieldgroups_id', $item->id, \PDO::PARAM_INT);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$rows = $query->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
$query->closeCursor();
|
||||||
|
|
||||||
|
$sql =
|
||||||
|
'UPDATE fieldgroups_fields SET data=:data ' .
|
||||||
|
'WHERE fieldgroups_id=:fieldgroups_id ' .
|
||||||
|
'AND fields_id=:fields_id AND sort=:sort';
|
||||||
|
|
||||||
|
$query = $database->prepare($sql);
|
||||||
|
|
||||||
|
foreach($rows as $row) {
|
||||||
|
$query->bindValue(':data', $row['data']);
|
||||||
|
$query->bindValue(':fieldgroups_id', (int) $fieldgroup->id, \PDO::PARAM_INT);
|
||||||
|
$query->bindValue(':fields_id', (int) $row['fields_id'], \PDO::PARAM_INT);
|
||||||
|
$query->bindValue(':sort', (int) $row['sort'], \PDO::PARAM_INT);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fieldgroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -619,4 +646,3 @@ class Fieldgroups extends WireSaveableItemsLookup {
|
|||||||
*/
|
*/
|
||||||
public function ___fieldRemoved(Fieldgroup $fieldgroup, Field $field) { }
|
public function ___fieldRemoved(Fieldgroup $fieldgroup, Field $field) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user