Skip to content

Commit

Permalink
Merge branch 'release/4.0.0-beta.1' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welch committed Mar 17, 2022
2 parents d90d98a + d0630c0 commit e7fd547
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 178 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Units Changelog

## 4.0.0-beta.1 - 2022.03.17

### Added

* Initial Craft CMS 4 compatibility

## 1.0.4 - 2020-10-27
### Fixed
- Fixed Composer 2 compatibility
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nystudio107/craft-units/badges/quality-score.png?b=v1)](https://scrutinizer-ci.com/g/nystudio107/craft-units/?branch=v1) [![Code Coverage](https://scrutinizer-ci.com/g/nystudio107/craft-units/badges/coverage.png?b=v1)](https://scrutinizer-ci.com/g/nystudio107/craft-units/?branch=v1) [![Build Status](https://scrutinizer-ci.com/g/nystudio107/craft-units/badges/build.png?b=v1)](https://scrutinizer-ci.com/g/nystudio107/craft-units/build-status/v1) [![Code Intelligence Status](https://scrutinizer-ci.com/g/nystudio107/craft-units/badges/code-intelligence.svg?b=v1)](https://scrutinizer-ci.com/code-intelligence)

# Units plugin for Craft CMS 3.x
# Units plugin for Craft CMS 4.x

Units is a plugin that can convert between any units of measure, and comes with a Field for content authors to use.

![Screenshot](./docs/docs/resources/img/plugin-logo.png)

## Requirements

This plugin requires Craft CMS 3.0.0 or later.
This plugin requires Craft CMS 4.0.0 or later.

## Installation

Expand Down
82 changes: 39 additions & 43 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
{
"name": "nystudio107/craft-units",
"description": "Units is a plugin that can convert between any units of measure, and comes with a Field for content authors to use",
"type": "craft-plugin",
"version": "1.0.4",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"measurement",
"measures",
"units",
"conversion"
],
"support": {
"docs": "https://nystudio107.com/plugins/units/documentation",
"issues": "https://nystudio107.com/plugins/units/support"
},
"license": "MIT",
"authors": [
{
"name": "nystudio107",
"homepage": "https://nystudio107.com/"
}
],
"require": {
"craftcms/cms": "^3.0.0",
"php-units-of-measure/php-units-of-measure": "^2.1.0"
},
"autoload": {
"psr-4": {
"nystudio107\\units\\": "src/"
}
},
"extra": {
"name": "Units",
"handle": "units",
"hasCpSettings": true,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/nystudio107/craft-units/master/CHANGELOG.md",
"components": {
},
"class": "nystudio107\\units\\Units"
"name": "nystudio107/craft-units",
"description": "Units is a plugin that can convert between any units of measure, and comes with a Field for content authors to use",
"type": "craft-plugin",
"version": "4.0.0-beta.1",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"measurement",
"measures",
"units",
"conversion"
],
"support": {
"docs": "https://nystudio107.com/docs/units/",
"issues": "https://nystudio107.com/plugins/units/support",
"source": "https://github.com/nystudio107/craft-typogrify"
},
"license": "MIT",
"authors": [
{
"name": "nystudio107",
"homepage": "https://nystudio107.com/"
}
],
"require": {
"craftcms/cms": "^4.0.0-beta.1",
"php-units-of-measure/php-units-of-measure": "^2.1.0"
},
"autoload": {
"psr-4": {
"nystudio107\\units\\": "src/"
}
},
"extra": {
"class": "nystudio107\\units\\Units",
"handle": "units",
"name": "Units"
}
}
50 changes: 23 additions & 27 deletions src/Units.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@

namespace nystudio107\units;

use nystudio107\units\fields\Units as UnitsField;
use nystudio107\units\helpers\ClassHelper;
use nystudio107\units\models\Settings;
use nystudio107\units\variables\UnitsVariable;

use Craft;
use craft\base\Model;
use craft\base\Plugin;
use craft\events\PluginEvent;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;
use craft\services\Plugins;
use craft\web\twig\variables\CraftVariable;

use yii\base\Event;

use nystudio107\units\fields\Units as UnitsField;
use nystudio107\units\helpers\ClassHelper;
use nystudio107\units\models\Settings;
use nystudio107\units\variables\UnitsVariable;
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
use yii\base\Event;

/**
* Class Units
Expand Down Expand Up @@ -57,21 +53,30 @@ class Units extends Plugin
*/
public string $schemaVersion = '1.0.0';

/**
* @var bool
*/
public bool $hasCpSettings = true;
/**
* @var bool
*/
public bool $hasCpSection = false;

// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function init()
public function init(): void
{
parent::init();
self::$plugin = $this;

Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
function (RegisterComponentTypesEvent $event) {
static function (RegisterComponentTypesEvent $event) {
$event->types[] = UnitsField::class;
}
);
Expand All @@ -80,30 +85,21 @@ function (RegisterComponentTypesEvent $event) {
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
static function (Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('units', self::$variable);
}
);

Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
}
}
);

Event::on(
UnitsField::class,
'craftQlGetFieldSchema',
function ($event) {
static function ($event) {
$field = $event->sender;

if (!$field instanceof UnitsField) {
return;
return;
}

$object = $event->schema->createObjectType(ucfirst($field->handle) . 'Units');
Expand Down Expand Up @@ -131,7 +127,7 @@ function ($event) {
/**
* @inheritdoc
*/
protected function createSettingsModel(): ?\craft\base\Model
protected function createSettingsModel(): ?Model
{
return new Settings();
}
Expand All @@ -146,8 +142,8 @@ protected function settingsHtml(): ?string
'units/settings',
[
'settings' => $this->getSettings(),
'unitsClassMap' => $unitsClassMap,
]
'unitsClassMap' => $unitsClassMap,
]
);
}
}
3 changes: 1 addition & 2 deletions src/assetbundles/units/UnitsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace nystudio107\units\assetbundles\units;

use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

Expand All @@ -27,7 +26,7 @@ class UnitsAsset extends AssetBundle
/**
* @inheritdoc
*/
public function init()
public function init(): void
{
$this->sourcePath = "@nystudio107/units/assetbundles/units/dist";

Expand Down
3 changes: 1 addition & 2 deletions src/assetbundles/unitsfield/UnitsFieldAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace nystudio107\units\assetbundles\unitsfield;

use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

Expand All @@ -27,7 +26,7 @@ class UnitsFieldAsset extends AssetBundle
/**
* @inheritdoc
*/
public function init()
public function init(): void
{
$this->sourcePath = "@nystudio107/units/assetbundles/unitsfield/dist";

Expand Down
10 changes: 4 additions & 6 deletions src/controllers/UnitsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

namespace nystudio107\units\controllers;

use nystudio107\units\Units;

use craft\web\Controller;

use nystudio107\units\Units;
use yii\web\Response;

/**
Expand All @@ -38,9 +36,9 @@ class UnitsController extends Controller
// =========================================================================

/**
* Return all of the available units as JSON
* Return all the available units as JSON
*
* @param bool $includeAliases whether to include aliases or not
* @param bool $includeAliases whether to include aliases or not
*
* @return Response
*/
Expand All @@ -53,7 +51,7 @@ public function actionAllAvailableUnits(bool $includeAliases = false): Response
* Return the available units for a given AbstractPhysicalQuantity as JSON
*
* @param string $unitsClass
* @param bool $includeAliases whether to include aliases or not
* @param bool $includeAliases whether to include aliases or not
*
* @return Response
*/
Expand Down
Loading

0 comments on commit e7fd547

Please sign in to comment.