Skip to content

Commit

Permalink
Update to craft 4
Browse files Browse the repository at this point in the history
  • Loading branch information
marionnewlevant committed Feb 12, 2023
1 parent 6c4faac commit 61d627d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 75 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand All @@ -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' => [
Expand All @@ -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}) %}
```
Expand All @@ -57,6 +57,5 @@ Settings defined in config/general.php:
<title>{{ craft.megaMerge.value('title') }}</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/)
80 changes: 40 additions & 40 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 4 additions & 4 deletions src/MegaMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,7 +31,7 @@
* @package MegaMerge
* @since 1.0.0
*
* @property MegaMergeServiceService $megaMergeService
* @property MegaMergeService $megaMergeService
*/
class MegaMerge extends Plugin
{
Expand All @@ -49,15 +49,15 @@ class MegaMerge extends Plugin
/**
* @var string
*/
public $schemaVersion = '1.0.0';
public string $schemaVersion = '1.0.0';

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

/**
* @inheritdoc
*/
public function init()
public function init(): void
{
parent::init();
self::$plugin = $this;
Expand Down
50 changes: 25 additions & 25 deletions src/fields/MegaMergeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Craft;
use craft\fields\Table;
use craft\helpers\Cp;
use craft\helpers\Json;
use craft\web\assets\tablesettings\TableSettingsAsset;

Expand All @@ -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',
Expand All @@ -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
Expand All @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 61d627d

Please # to comment.