Skip to content

Instantly share code, notes, and snippets.

@flydev-fr
Last active December 18, 2018 10:11
Show Gist options
  • Save flydev-fr/767669a226df380fd0c1000a4d43e4e6 to your computer and use it in GitHub Desktop.
Save flydev-fr/767669a226df380fd0c1000a4d43e4e6 to your computer and use it in GitHub Desktop.
↪️ Hook to add FieldtypeDecimal to compatible fieldtypes of a FieldtypeFloat when a superuser need to change the type of an existing float field - ProcessWire
/**
* Hook : place this hook in admin.php
*
* Add FieldtypeDecimal to compatible fieldtypes of
* a FieldtypeFloat when a superuser need to change the type
* of a float field.
*
* https://modules.processwire.com/modules/fieldtype-decimal/
* https://processwire.com/talk/topic/7542-development-fieldtypefloat-fieldtypedecimal/
*
*/
$wire->addHookAfter('FieldtypeFloat::getCompatibleFieldtypes', function($event) {
if(!$this->modules->isInstalled('FieldtypeDecimal') || !$this->user->isSuperuser()) return;
$return = $event->return;
$return->set('FieldtypeDecimal', $this->modules->get('FieldtypeDecimal'));
$event->return = $return;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment