mirror of
https://github.com/processwire/processwire.git
synced 2025-08-19 13:01:26 +02:00
Fix issue processwire/processwire-issues#667 where cloning a FieldtypeOptions field was only cloning the field, and not the options.
This commit is contained in:
@@ -420,6 +420,40 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a cloned copy of $field
|
||||
*
|
||||
* @param Field $field
|
||||
* @return Field cloned copy
|
||||
*
|
||||
*/
|
||||
public function ___cloneField(Field $field) {
|
||||
$this->wire('fields')->addHookAfter('cloned', $this, 'hookCloned');
|
||||
return parent::___cloneField($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called when field is cloned, to clone the selectable options from old field to new field
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param HookEvent $event
|
||||
*
|
||||
*/
|
||||
public function hookCloned(HookEvent $event) {
|
||||
/** @var Field $oldField */
|
||||
$oldField = $event->arguments(0);
|
||||
/** @var Field $newField */
|
||||
$newField = $event->arguments(1);
|
||||
/** @var FieldtypeOptions $fieldtype */
|
||||
$fieldtype = $oldField->type;
|
||||
if(!$fieldtype instanceof FieldtypeOptions) return;
|
||||
$options = $fieldtype->getOptions($oldField);
|
||||
$options->setField($newField);
|
||||
$fieldtype->addOptions($newField, $options);
|
||||
$event->removeHook(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Inputfields needed to configure this Fieldtype
|
||||
*
|
||||
|
Reference in New Issue
Block a user