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 d553156..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", @@ -28,7 +28,8 @@ } ], "require": { - "craftcms/cms": "^3.2.0" + "craftcms/cms": "^3.2.0", + "nystudio107/craft-twigfield": "^1.0.0" }, "autoload": { "psr-4": { diff --git a/src/fields/PreparseFieldType.php b/src/fields/PreparseFieldType.php index 2db8fe0..502d5c5 100644 --- a/src/fields/PreparseFieldType.php +++ b/src/fields/PreparseFieldType.php @@ -74,26 +74,24 @@ public static function displayName(): string public function rules() { $rules = parent::rules(); - $rules = 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], - ]); - - 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], + ]); } /** @@ -108,7 +106,7 @@ public function getContentColumnType(): string return $this->columnType; } - + /** * @return null|string * @throws LoaderError @@ -143,7 +141,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 fd77ec4..dbfd1fe 100644 --- a/src/templates/_components/fields/_settings.twig +++ b/src/templates/_components/fields/_settings.twig @@ -13,16 +13,17 @@ #} {% 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.\nIf the column type is set to Date (datetime), the parsed Twig should output a date formatted as `Y-m-d H:i:s`."|t, id: 'fieldTwig', name: 'fieldTwig', value: field['fieldTwig'], class: 'code', - rows: 10 -}) }} + rows: 10, +}, "Twigfield", "monaco-editor-background-frame") }} {% set columnType %} {{ forms.select({