From e1c04fcfc7389c52a3a1ad22f110e55fc4fef2f4 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sun, 12 Jun 2022 03:35:02 -0400 Subject: [PATCH 1/5] refactor: Add support for craft-twigfield --- composer.json | 3 ++- src/templates/_components/fields/_settings.twig | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 0a9fa21..a8f5ce1 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ } ], "require": { - "craftcms/cms": "^3.2.0" + "craftcms/cms": "^3.2.0", + "nystudio107/craft-twigfield": "dev-develop" }, "autoload": { "psr-4": { diff --git a/src/templates/_components/fields/_settings.twig b/src/templates/_components/fields/_settings.twig index 831c878..06862eb 100644 --- a/src/templates/_components/fields/_settings.twig +++ b/src/templates/_components/fields/_settings.twig @@ -13,8 +13,9 @@ #} {% import "_includes/forms" as forms %} +{% import "twigfield/twigfield" as twigfield %} -{{ forms.textareaField( { +{{ twigfield.textareaField( { label: "Twig code to parse"|t, instructions: "Enter the twig code that you want to parse after the entry has been saved."|t, id: 'fieldTwig', @@ -22,7 +23,7 @@ value: field['fieldTwig'], class: 'code', rows: 10 -}) }} +}, "Twigfield", "monaco-editor-background-frame") }} {% set columnType %} {{ forms.select({ From 6f100e344491ba705346e9f4dbd01076e3c0412c Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 14 Jun 2022 15:57:48 -0400 Subject: [PATCH 2/5] refactor: Bump semver to `^1.0.0` for release version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a8f5ce1..bb1e332 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ ], "require": { "craftcms/cms": "^3.2.0", - "nystudio107/craft-twigfield": "dev-develop" + "nystudio107/craft-twigfield": "^1.0.0" }, "autoload": { "psr-4": { From 6ac04669ae7f1b3ebb2d249be703de53b0ab7ee0 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 14 Jun 2022 16:10:26 -0400 Subject: [PATCH 3/5] feat: Add TwigTemplateValidator --- src/fields/PreparseFieldType.php | 8 ++++---- src/templates/_components/fields/_settings.twig | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/fields/PreparseFieldType.php b/src/fields/PreparseFieldType.php index 7baded1..b423ede 100644 --- a/src/fields/PreparseFieldType.php +++ b/src/fields/PreparseFieldType.php @@ -15,6 +15,7 @@ use craft\base\SortableFieldInterface; use craft\db\mysql\Schema; use craft\helpers\Db; +use nystudio107\twigfield\validators\TwigTemplateValidator; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; @@ -70,8 +71,7 @@ public function rules() { $rules = parent::rules(); $rules = array_merge($rules, [ - ['fieldTwig', 'string'], - ['fieldTwig', 'default', 'value' => ''], + ['fieldTwig', TwigTemplateValidator::class], ['columnType', 'string'], ['columnType', 'default', 'value' => ''], ['decimals', 'number'], @@ -103,7 +103,7 @@ public function getContentColumnType(): string return $this->columnType; } - + /** * @return null|string * @throws LoaderError @@ -137,7 +137,7 @@ public function getSettingsHtml() ] ); } - + /** * @param mixed $value * @param ElementInterface|null $element diff --git a/src/templates/_components/fields/_settings.twig b/src/templates/_components/fields/_settings.twig index 06862eb..428cd52 100644 --- a/src/templates/_components/fields/_settings.twig +++ b/src/templates/_components/fields/_settings.twig @@ -20,9 +20,10 @@ instructions: "Enter the twig code that you want to parse after the entry has been saved."|t, id: 'fieldTwig', name: 'fieldTwig', - value: field['fieldTwig'], + value: field.fieldTwig, class: 'code', - rows: 10 + rows: 10, + errors: field.getErrors('fieldTwig'), }, "Twigfield", "monaco-editor-background-frame") }} {% set columnType %} From a6d85ac27619cef78cafff8ef6b3bb1fa2e20d26 Mon Sep 17 00:00:00 2001 From: Jalen Davenport Date: Mon, 8 Aug 2022 08:40:46 -0400 Subject: [PATCH 4/5] Remove twig field validation until I can find a better solution --- src/fields/PreparseFieldType.php | 38 +++++++++---------- .../_components/fields/_settings.twig | 3 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/fields/PreparseFieldType.php b/src/fields/PreparseFieldType.php index b423ede..903b2d0 100644 --- a/src/fields/PreparseFieldType.php +++ b/src/fields/PreparseFieldType.php @@ -15,7 +15,6 @@ use craft\base\SortableFieldInterface; use craft\db\mysql\Schema; use craft\helpers\Db; -use nystudio107\twigfield\validators\TwigTemplateValidator; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; @@ -70,25 +69,24 @@ public static function displayName(): string public function rules() { $rules = parent::rules(); - $rules = array_merge($rules, [ - ['fieldTwig', TwigTemplateValidator::class], - ['columnType', 'string'], - ['columnType', 'default', 'value' => ''], - ['decimals', 'number'], - ['decimals', 'default', 'value' => 0], - ['textareaRows', 'number'], - ['textareaRows', 'default', 'value' => 5], - ['parseBeforeSave', 'boolean'], - ['parseBeforeSave', 'default', 'value' => false], - ['parseOnMove', 'boolean'], - ['parseOnMove', 'default', 'value' => false], - ['displayType', 'string'], - ['displayType', 'default', 'value' => 'hidden'], - ['allowSelect', 'boolean'], - ['allowSelect', 'default', 'value' => false], - ]); - - return $rules; + return array_merge($rules, [ + ['fieldTwig', 'string'], + ['fieldTwig', 'default', 'value' => ''], + ['columnType', 'string'], + ['columnType', 'default', 'value' => ''], + ['decimals', 'number'], + ['decimals', 'default', 'value' => 0], + ['textareaRows', 'number'], + ['textareaRows', 'default', 'value' => 5], + ['parseBeforeSave', 'boolean'], + ['parseBeforeSave', 'default', 'value' => false], + ['parseOnMove', 'boolean'], + ['parseOnMove', 'default', 'value' => false], + ['displayType', 'string'], + ['displayType', 'default', 'value' => 'hidden'], + ['allowSelect', 'boolean'], + ['allowSelect', 'default', 'value' => false], + ]); } /** diff --git a/src/templates/_components/fields/_settings.twig b/src/templates/_components/fields/_settings.twig index 428cd52..0683816 100644 --- a/src/templates/_components/fields/_settings.twig +++ b/src/templates/_components/fields/_settings.twig @@ -20,10 +20,9 @@ instructions: "Enter the twig code that you want to parse after the entry has been saved."|t, id: 'fieldTwig', name: 'fieldTwig', - value: field.fieldTwig, + value: field['fieldTwig'], class: 'code', rows: 10, - errors: field.getErrors('fieldTwig'), }, "Twigfield", "monaco-editor-background-frame") }} {% set columnType %} From b78856bc8e31428eca89171a0a3ea9e9051b01ba Mon Sep 17 00:00:00 2001 From: Jalen Davenport Date: Mon, 8 Aug 2022 08:46:53 -0400 Subject: [PATCH 5/5] Prepare 1.4.0 release --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e60a53..38d232b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.4.0 - 2022-08-08 +### Added +- Added support for craft-twigfield ([#81](https://github.com/besteadfast/craft-preparse-field/pull/81) - thanks @khalwat) + ## 1.3.0 - 2022-08-06 ### Added - Added datetime column type option ([#63](https://github.com/besteadfast/craft-preparse-field/pull/63) - thanks @mmikkel) diff --git a/composer.json b/composer.json index cc78360..4b41c90 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "besteadfast/craft-preparse-field", "description": "A fieldtype that parses Twig when an element is saved and saves the result as plain text.", "type": "craft-plugin", - "version": "1.3.0", + "version": "1.4.0", "keywords": [ "craft", "cms",