From 61d627d5289200cab321dd9d77bf0dfd5309e4ff Mon Sep 17 00:00:00 2001 From: Marion Newlevant Date: Sat, 11 Feb 2023 17:01:41 -0800 Subject: [PATCH] Update to craft 4 --- CHANGELOG.md | 8 ++++ README.md | 11 +++-- composer.json | 80 +++++++++++++++++------------------ src/MegaMerge.php | 8 ++-- src/fields/MegaMergeField.php | 50 +++++++++++----------- 5 files changed, 82 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 335a52b..05ec533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # MegaMerge Changelog +## 2.0.0 - 2023.02.11 + +### Added + +- Ported to Craft 4 + ## 1.0.0 - 2019-01-19 + ### Added + - Initial release diff --git a/README.md b/README.md index 7c7dfae..119a9a4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MegaMerge plugin for Craft CMS 3.x +# MegaMerge plugin for Craft CMS 4.x MegaMerge: [merge]() MegaMerge provides a fieldtype which is a Craft table with predefined `Key` and `Value` columns. It lets you merge together those fields with php arrays and twig arrays, and then look up values of keys in the merged array. The resultant values are parsed as twig. @@ -7,7 +7,7 @@ This is a general purpose utility, though one of its potential uses (and the one ## Requirements -This plugin requires Craft CMS 3.0.0 or later. +This plugin requires Craft CMS 4.0.0 or later. ## Installation @@ -30,11 +30,11 @@ MegaMerge provides a fieldtype (a key/value table) and three functions: ## Using MegaMerge -**The key/value pairs** A megaMerge field called `globalSettings` in the `g_configuration` global set: +**The key/value pairs** A megaMerge field called `globalSettings` in the `g_configuration` global set: ![megaMergeField](docs/megaMergeField.png) -Settings defined in config/general.php: +Settings defined in config/custom.php: ```php 'megaMerge' => [ @@ -46,7 +46,7 @@ Settings defined in config/general.php: ```twig {% do craft.megaMerge.init([ - craft.app.config.general.megaMerge, + craft.app.config.custom.megaMerge, g_configuration.globalSettings ], {object: entry}) %} ``` @@ -57,6 +57,5 @@ Settings defined in config/general.php: {{ craft.megaMerge.value('title') }} ``` - Brought to you by [Marion Newlevant](http://marion.newlevant.com). Icon insides by [Dmitry Baranovskiy from the Noun Project](https://thenounproject.com/term/merge/5026/) diff --git a/composer.json b/composer.json index 8a9f761..7f0e3e3 100644 --- a/composer.json +++ b/composer.json @@ -1,43 +1,43 @@ { - "name": "marionnewlevant/mega-merge", - "description": "Merge this that and the other... With twig parsing", - "type": "craft-plugin", - "version": "1.0.0", - "keywords": [ - "craft", - "cms", - "craftcms", - "craft-plugin", - "megamerge" - ], - "support": { - "docs": "https://github.com/craft-megamerge/mega-merge/blob/master/README.md", - "issues": "https://github.com/craft-megamerge/mega-merge/issues" - }, - "license": "MIT", - "authors": [ - { - "name": "Marion Newlevant", - "homepage": "http://marion.newlevant.com" - } - ], - "require": { - "craftcms/cms": "^3.0.0-RC1" - }, - "autoload": { - "psr-4": { - "marionnewlevant\\megamerge\\": "src/" - } - }, - "extra": { - "name": "MegaMerge", - "handle": "mega-merge", - "hasCpSettings": false, - "hasCpSection": false, - "changelogUrl": "https://raw.githubusercontent.com/craft-megamerge/mega-merge/master/CHANGELOG.md", - "components": { - "megaMergeService": "marionnewlevant\\megamerge\\services\\MegaMergeService" - }, - "class": "marionnewlevant\\megamerge\\MegaMerge" + "name": "marionnewlevant/mega-merge", + "description": "Merge this that and the other... With twig parsing", + "type": "craft-plugin", + "version": "2.0.0", + "keywords": [ + "craft", + "cms", + "craftcms", + "craft-plugin", + "megamerge" + ], + "support": { + "docs": "https://github.com/craft-megamerge/mega-merge/blob/v2/README.md", + "issues": "https://github.com/craft-megamerge/mega-merge/issues" + }, + "license": "MIT", + "authors": [ + { + "name": "Marion Newlevant", + "homepage": "http://marion.newlevant.com" } + ], + "require": { + "craftcms/cms": "^4.0" + }, + "autoload": { + "psr-4": { + "marionnewlevant\\megamerge\\": "src/" + } + }, + "extra": { + "name": "MegaMerge", + "handle": "mega-merge", + "hasCpSettings": false, + "hasCpSection": false, + "changelogUrl": "https://raw.githubusercontent.com/craft-megamerge/mega-merge/v2/CHANGELOG.md", + "components": { + "megaMergeService": "marionnewlevant\\megamerge\\services\\MegaMergeService" + }, + "class": "marionnewlevant\\megamerge\\MegaMerge" + } } diff --git a/src/MegaMerge.php b/src/MegaMerge.php index 55be179..4b2c547 100644 --- a/src/MegaMerge.php +++ b/src/MegaMerge.php @@ -10,7 +10,7 @@ namespace marionnewlevant\megamerge; -use marionnewlevant\megamerge\services\MegaMergeService as MegaMergeServiceService; +use marionnewlevant\megamerge\services\MegaMergeService; use marionnewlevant\megamerge\variables\MegaMergeVariable; use marionnewlevant\megamerge\fields\MegaMergeField as MegaMergeFieldField; @@ -31,7 +31,7 @@ * @package MegaMerge * @since 1.0.0 * - * @property MegaMergeServiceService $megaMergeService + * @property MegaMergeService $megaMergeService */ class MegaMerge extends Plugin { @@ -49,7 +49,7 @@ class MegaMerge extends Plugin /** * @var string */ - public $schemaVersion = '1.0.0'; + public string $schemaVersion = '1.0.0'; // Public Methods // ========================================================================= @@ -57,7 +57,7 @@ class MegaMerge extends Plugin /** * @inheritdoc */ - public function init() + public function init(): void { parent::init(); self::$plugin = $this; diff --git a/src/fields/MegaMergeField.php b/src/fields/MegaMergeField.php index d6f8c80..f437837 100644 --- a/src/fields/MegaMergeField.php +++ b/src/fields/MegaMergeField.php @@ -14,6 +14,7 @@ use Craft; use craft\fields\Table; +use craft\helpers\Cp; use craft\helpers\Json; use craft\web\assets\tablesettings\TableSettingsAsset; @@ -30,7 +31,7 @@ class MegaMergeField extends Table /** * @var array|null The columns that should be shown in the table */ - public $columns = [ + public array $columns = [ 'col1' => [ 'heading' => 'Key', 'handle' => 'key', @@ -48,7 +49,7 @@ class MegaMergeField extends Table /** * @var array The default row values that new elements should have */ - public $defaults = [ + public ?array $defaults = [ ]; // Static Methods @@ -68,7 +69,7 @@ public static function displayName(): string /** * @inheritdoc */ - public function getSettingsHtml() + public function getSettingsHtml(): ?string { $typeOptions = [ 'multiline' => Craft::t('app', 'Multi-line text'), @@ -114,32 +115,31 @@ public function getSettingsHtml() Json::encode($columnSettings, JSON_UNESCAPED_UNICODE) . ');'); - $columnsField = $view->renderTemplateMacro('_includes/forms', 'editableTableField', [ - [ - 'label' => Craft::t('app', 'Table Columns'), - 'instructions' => Craft::t('mega-merge', 'These are the columns your table will have.'), - 'id' => 'columns', - 'name' => 'columns', - 'cols' => $columnSettings, - 'rows' => $this->columns, - 'initJs' => false, - 'static' => true // make it not editable - ] + $columnsField = Cp::editableTableFieldHtml([ + 'label' => Craft::t('app', 'Table Columns'), + 'instructions' => Craft::t('mega-merge', 'These are the columns your table will have.'), + 'id' => 'columns', + 'name' => 'columns', + 'cols' => $columnSettings, + 'rows' => $this->columns, + 'initJs' => false, + 'static' => true // make it not editable ]); - $defaultsField = $view->renderTemplateMacro('_includes/forms', 'editableTableField', [ - [ - 'label' => Craft::t('app', 'Default Values'), - 'instructions' => Craft::t('app', 'Define the default values for the field.'), - 'id' => 'defaults', - 'name' => 'defaults', - 'cols' => $this->columns, - 'rows' => $this->defaults, - 'initJs' => false - ] + $defaultsField = Cp::editableTableFieldHtml([ + 'label' => Craft::t('app', 'Default Values'), + 'instructions' => Craft::t('app', 'Define the default values for the field.'), + 'id' => 'defaults', + 'name' => 'defaults', + 'allowAdd' => true, + 'allowReorder' => true, + 'allowDelete' => true, + 'cols' => $this->columns, + 'rows' => $this->defaults, + 'initJs' => false ]); - return $view->renderTemplate('_components/fieldtypes/Table/settings', [ + return $view->renderTemplate('_components/fieldtypes/Table/settings.twig', [ 'field' => $this, 'columnsField' => $columnsField, 'defaultsField' => $defaultsField,