nystudio107 / craft-units

Units is a plugin that can convert between any units of measure, and comes with a Field for content authors to use
https://nystudio107.com/
MIT License
9 stars 2 forks source link

Support for additional units #44

Closed AndrewMac closed 1 year ago

AndrewMac commented 1 year ago

Question

Is there any way to extend the plugin with additional units?

Additional context

I have a site that records property sizes in "rai", which is how Thai people measure area. Most of my editors want to input the area in rai, which is what customers give them, but sometimes they give the size in acres or square metres. So we'd really appreciate the flexibility of this Units plugin, but only if we can extend it to support Rai as well.

Thanks in advance for any help or advice you may be able to give with this.

Andrew Macpherson

khalwat commented 1 year ago

So because we use this library under the hood:

https://github.com/PhpUnitsOfMeasure/php-units-of-measure

It is actually quite doable to add units even at runtime, if you're willing to write some PHP code to make it happen.

AndrewMac commented 1 year ago

Ah, okay, and thanks again! I took a quick look — do you think we would be able to add the new unit to the edit screen by creating a custom module, then? Using the example in the "Adding new Units of Measure to Existing Quantities" section at that link?

The reason is that, if possible, we need our editors to be able to pick that new unit when necessary while adding the details in the field (they get the data in different units). I know that's probably too much to expect with your plugin, which you've been kind enough to offer for free, so if you that's the right direction to go in then we won't trouble you again. And, if our coding skills are not quite up to it, well, we'll just have to look for alternative solutions :-)

Cheers, Andrew

khalwat commented 1 year ago

Yeah, I've never done it, but it should "just work" because the Units plugin dynamically asks the library for what units of measure are available. So if you add a new unit of measure in a module, it should just show up and work everywhere.

Happy to help if any small patches need to be made to make it happen for you.