diff --git a/CHANGELOG.md b/CHANGELOG.md index 685decf..a164a5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.4.0](https://github.com/flextype-plugins/form/compare/v1.3.0...v1.4.0) (2020-08-19) + +### Features + +* **core** update code base for new Flextype 0.9.10 + # [1.3.0](https://github.com/flextype-plugins/form/compare/v1.2.1...v1.3.0) (2020-08-09) diff --git a/README.md b/README.md index 775fa72..8131b8e 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Form Plugin for Flextype

-Version License Total downloads Flextype Quality Score Discord +Version License Total downloads Flextype Quality Score Discord

Form Plugin to render user forms for Flextype. @@ -12,7 +12,7 @@ The following dependencies need to be installed for Form Plugin. | Item | Version | Download | |---|---|---| -| [flextype](https://github.com/flextype/flextype) | 0.9.9 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) | | [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) | | [jquery](https://github.com/flextype-plugins/jquery) | >=1.0.0 | [download](https://github.com/flextype-plugins/jquery/releases) | @@ -491,13 +491,13 @@ form: use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -$app->post('{uri:.+}', function(Request $request, Response $response) use ($flextype) { +$flextype->post('{uri:.+}', function(Request $request, Response $response) use ($flextype) { // get post data $post_data = $request->getParsedBody(); // save date from $post_data - $flextype['entries']->create($post_data['name'], ['title' => $post_data['name']]); + $flextype->container()['entries']->create($post_data['name'], ['title' => $post_data['name']]); // redirect return $response->withRedirect('./'); diff --git a/app/Models/Fieldsets.php b/app/Models/Fieldsets.php index 6840e48..fe70744 100644 --- a/app/Models/Fieldsets.php +++ b/app/Models/Fieldsets.php @@ -9,7 +9,6 @@ namespace Flextype\Plugin\Form\Models; -use Flextype\App\Foundation\Container; use Flextype\Component\Filesystem\Filesystem; use function count; use function rename; @@ -17,9 +16,9 @@ class Fieldsets { /** - * Flextype Dependency Container + * Flextype Application */ - private $flextype; + protected $flextype; /** * Constructor @@ -34,9 +33,11 @@ public function __construct($flextype) Filesystem::createDir($this->getDirLocation()); } - if (! Filesystem::has($this->getFileLocation('default'))) { - Filesystem::copy(PATH['project'] . '/plugins/form/fieldsets/samples/default/default.yaml', $this->getFileLocation('default')); + if (Filesystem::has($this->getFileLocation('default'))) { + return; } + + Filesystem::copy(PATH['project'] . '/plugins/form/fieldsets/samples/default/default.yaml', $this->getFileLocation('default')); } /** @@ -54,7 +55,7 @@ public function fetch(string $id) if (Filesystem::has($fieldset_file)) { if ($fieldset_body = Filesystem::read($fieldset_file)) { - if ($fieldset_decoded = $this->flextype['yaml']->decode($fieldset_body)) { + if ($fieldset_decoded = $this->flextype->container('yaml')->decode($fieldset_body)) { return $fieldset_decoded; } @@ -89,7 +90,7 @@ public function fetchAll() : array continue; } - $fieldset_content = $this->flextype['yaml']->decode(Filesystem::read($fieldset['path'])); + $fieldset_content = $this->flextype->container('yaml')->decode(Filesystem::read($fieldset['path'])); $fieldsets[$fieldset['basename']] = $fieldset_content['title']; } } @@ -110,11 +111,11 @@ public function fetchAll() : array */ public function rename(string $id, string $new_id) : bool { - if (!Filesystem::has($this->getFileLocation($new_id))) { + if (! Filesystem::has($this->getFileLocation($new_id))) { return rename($this->getFileLocation($id), $this->getFileLocation($new_id)); - } else { - return false; } + + return false; } /** @@ -132,7 +133,7 @@ public function update(string $id, array $data) : bool $fieldset_file = $this->getFileLocation($id); if (Filesystem::has($fieldset_file)) { - return Filesystem::write($fieldset_file, $this->flextype['yaml']->encode($data)); + return Filesystem::write($fieldset_file, $this->flextype->container('yaml')->encode($data)); } return false; @@ -153,7 +154,7 @@ public function create(string $id, array $data) : bool $fieldset_file = $this->getFileLocation($id); if (! Filesystem::has($fieldset_file)) { - return Filesystem::write($fieldset_file, $this->flextype['yaml']->encode($data)); + return Filesystem::write($fieldset_file, $this->flextype->container('yaml')->encode($data)); } return false; diff --git a/app/Models/Form.php b/app/Models/Form.php index c79e1eb..e18d1e6 100644 --- a/app/Models/Form.php +++ b/app/Models/Form.php @@ -11,24 +11,32 @@ namespace Flextype\Plugin\Form\Models; -use Flextype\App\Foundation\Container; use Flextype\Component\Arrays\Arrays; -use function count; -use function date; -use function Flextype\Component\I18n\__; use function str_replace; use function strlen; use function strpos; -use function strtotime; use function substr_replace; -class Form extends Container +class Form { + /** + * Flextype Application + */ + protected $flextype; + + /** + * __construct + */ + public function __construct($flextype) + { + $this->flextype = $flextype; + } + /** * Render form * - * @param array $fieldset Fieldset - * @param array $values Fieldset values + * @param array $fieldset Fieldset + * @param array $values Fieldset values * * @return string Returns form based on fieldset * @@ -36,12 +44,14 @@ class Form extends Container */ public function render(array $fieldset, array $values = []) : string { - return $this->twig->fetch('plugins/form/fieldsets/base.html', - [ - 'fieldset' => $fieldset, - 'values' => $values, - 'query' => $_GET - ]); + return $this->flextype->container('twig')->fetch( + 'plugins/form/fieldsets/base.html', + [ + 'fieldset' => $fieldset, + 'values' => $values, + 'query' => $_GET, + ] + ); } /** @@ -59,7 +69,7 @@ public function getElementValue(string $element, array $values, array $propertie { if (Arrays::has($values, $element)) { $field_value = Arrays::get($values, $element); - } elseif(Arrays::has($properties, 'default')) { + } elseif (Arrays::has($properties, 'default')) { $field_value = $properties['default']; } else { $field_value = ''; diff --git a/assets/src/select-tags/select-tags.js b/assets/src/select-tags/select-tags.js index 9839409..62da0b3 100644 --- a/assets/src/select-tags/select-tags.js +++ b/assets/src/select-tags/select-tags.js @@ -1,6 +1,6 @@ $('.js-select-tags').select2({tags: true, multiple: true, tokenSeparators: [',', ' ']}); $('.js-select-tags').on('change', function (e) { - $('.js-select-tags').each(function() { + $('.js-select-tags').each(function () { var name = $(this).attr('data-name'); $('input[name='+name+']').val($(this).val().toString()); }); diff --git a/composer.json b/composer.json index 5a68b83..96acd2f 100644 --- a/composer.json +++ b/composer.json @@ -16,13 +16,13 @@ "issues": "https://github.com/flextype/issues" }, "require": { - "php": ">=7.2.5" + "php": ">=7.3.0" }, "config": { "apcu-autoloader": true, "optimize-autoloader": true, "platform": { - "php": "7.2.5" + "php": "7.3.0" } }, "autoload": { diff --git a/dependencies.php b/dependencies.php index 533c30a..554d6c1 100644 --- a/dependencies.php +++ b/dependencies.php @@ -11,54 +11,65 @@ namespace Flextype\Plugin\Form; -use Flextype\Plugin\Form\Models\Form; use Flextype\Plugin\Form\Models\Fieldsets; +use Flextype\Plugin\Form\Models\Form; use Flextype\Plugin\Form\Twig\FormTwigExtension; +use function array_merge; +use function strtolower; +use function substr; /** * Add Form Model to Flextype container */ -$flextype['form'] = static function ($container) { - return new Form($container); +$flextype->container()['form'] = static function () use ($flextype) { + return new Form($flextype); }; /** * Add Fieldsets Model to Flextype container */ -$flextype['fieldsets'] = static function ($container) { - return new Fieldsets($container); +$flextype->container()['fieldsets'] = static function () use ($flextype) { + return new Fieldsets($flextype); }; /** * Add Form Twig extension */ -$flextype->twig->addExtension(new FormTwigExtension($flextype)); +$flextype->container('twig')->addExtension(new FormTwigExtension($flextype)); /** * Add Assets */ -$_admin_css = ($flextype['registry']->has('assets.admin.css')) ? $flextype['registry']->get('assets.admin.css') : []; -$_site_css = ($flextype['registry']->has('assets.site.css')) ? $flextype['registry']->get('assets.site.css') : []; +$_admin_css = $flextype->container('registry')->has('assets.admin.css') ? $flextype->container('registry')->get('assets.admin.css') : []; +$_site_css = $flextype->container('registry')->has('assets.site.css') ? $flextype->container('registry')->get('assets.site.css') : []; -if ($flextype['registry']->get('plugins.form.settings.load_on_admin')) { - $flextype['registry']->set('assets.admin.css', - array_merge($_admin_css, ['project/plugins/form/assets/dist/css/form-vendor-build.min.css', - 'project/plugins/form/assets/dist/css/form-build.min.css'])); +if ($flextype->container('registry')->get('plugins.form.settings.load_on_admin')) { + $flextype->container('registry')->set( + 'assets.admin.css', + array_merge($_admin_css, [ + 'project/plugins/form/assets/dist/css/form-vendor-build.min.css', + 'project/plugins/form/assets/dist/css/form-build.min.css', + ]) + ); } -if ($flextype['registry']->get('plugins.form.settings.load_on_site')) { - $flextype['registry']->set('assets.site.css', - array_merge($_site_css, ['project/plugins/form/assets/dist/css/form-vendor-build.min.css', - 'project/plugins/form/assets/dist/css/form-build.min.css'])); +if ($flextype->container('registry')->get('plugins.form.settings.load_on_site')) { + $flextype->container('registry')->set( + 'assets.site.css', + array_merge($_site_css, [ + 'project/plugins/form/assets/dist/css/form-vendor-build.min.css', + 'project/plugins/form/assets/dist/css/form-build.min.css', + ]) + ); } -if ($flextype['registry']->get('flextype.settings.locale') == 'en_US') { +if ($flextype->container('registry')->get('flextype.settings.locale') === 'en_US') { $_locale = 'en'; } else { - $_locale = substr(strtolower($flextype['registry']->get('flextype.settings.locale')), 0, 2); + $_locale = substr(strtolower($flextype->container('registry')->get('flextype.settings.locale')), 0, 2); } -if ($_locale != 'en') { +if ($_locale !== 'en') { $trumbowyg_locale_js = 'project/plugins/form/assets/dist/lang/trumbowyg/langs/' . $_locale . '.min.js'; $flatpickr_locale_js = 'project/plugins/form/assets/dist/lang/flatpickr/l10n/' . $_locale . '.js'; } else { @@ -66,21 +77,29 @@ $flatpickr_locale_js = ''; } -$_admin_js = ($flextype['registry']->has('assets.admin.js')) ? $flextype['registry']->get('assets.admin.js') : []; -$_site_js = ($flextype['registry']->has('assets.site.js')) ? $flextype['registry']->get('assets.site.js') : []; +$_admin_js = $flextype->container('registry')->has('assets.admin.js') ? $flextype->container('registry')->get('assets.admin.js') : []; +$_site_js = $flextype->container('registry')->has('assets.site.js') ? $flextype->container('registry')->get('assets.site.js') : []; -if ($flextype['registry']->get('plugins.form.settings.load_on_admin')) { - $flextype['registry']->set('assets.admin.js', - array_merge($_admin_js, ['project/plugins/form/assets/dist/js/form-vendor-build.min.js', - $trumbowyg_locale_js, - $flatpickr_locale_js, - 'project/plugins/form/assets/dist/js/form-build.min.js'])); +if ($flextype->container('registry')->get('plugins.form.settings.load_on_admin')) { + $flextype->container('registry')->set( + 'assets.admin.js', + array_merge($_admin_js, [ + 'project/plugins/form/assets/dist/js/form-vendor-build.min.js', + $trumbowyg_locale_js, + $flatpickr_locale_js, + 'project/plugins/form/assets/dist/js/form-build.min.js', + ]) + ); } -if ($flextype['registry']->get('plugins.form.settings.load_on_site')) { - $flextype['registry']->set('assets.site.js', - array_merge($_site_js, ['project/plugins/form/assets/dist/js/form-vendor-build.min.js', - $trumbowyg_locale_js, - $flatpickr_locale_js, - 'project/plugins/form/assets/dist/js/form-build.min.js'])); +if ($flextype->container('registry')->get('plugins.form.settings.load_on_site')) { + $flextype->container('registry')->set( + 'assets.site.js', + array_merge($_site_js, [ + 'project/plugins/form/assets/dist/js/form-vendor-build.min.js', + $trumbowyg_locale_js, + $flatpickr_locale_js, + 'project/plugins/form/assets/dist/js/form-build.min.js', + ]) + ); } diff --git a/gulpfile.js b/gulpfile.js index b12c1f7..822ee12 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,15 +1,15 @@ -const gulp = require('gulp'); +const gulp = require('gulp'); const tailwindConfig = "tailwind.config.js"; /** * Task: gulp vendor-css */ - gulp.task("vendor-css", function() { - const concat = require('gulp-concat'); - const csso = require('gulp-csso'); - const autoprefixer = require('gulp-autoprefixer'); + gulp.task("vendor-css", function () { + const concat = require('gulp-concat'); + const csso = require('gulp-csso'); + const autoprefixer = require('gulp-autoprefixer'); - return gulp + return gulp .src([ // Select2 'node_modules/select2/dist/css/select2.min.css', @@ -21,11 +21,11 @@ const tailwindConfig = "tailwind.config.js"; 'node_modules/trumbowyg/dist/ui/trumbowyg.min.css', 'node_modules/trumbowyg/dist/plugins/table/ui/trumbowyg.table.css']) .pipe(autoprefixer({ - overrideBrowserslist: [ + overrideBrowserslist: [ "last 1 version" - ], - cascade: false - })) + ], + cascade: false + })) .pipe(csso()) .pipe(concat('form-vendor-build.min.css')) .pipe(gulp.dest("assets/dist/css/")); @@ -35,16 +35,16 @@ const tailwindConfig = "tailwind.config.js"; /** * Task: gulp admin-panel-css */ -gulp.task('form-css', function() { - const concat = require('gulp-concat'); - const csso = require('gulp-csso'); - const sourcemaps = require('gulp-sourcemaps'); - const atimport = require("postcss-import"); - const postcss = require("gulp-postcss"); - const autoprefixer = require('gulp-autoprefixer'); - const tailwindcss = require("tailwindcss"); - - return gulp + gulp.task('form-css', function () { + const concat = require('gulp-concat'); + const csso = require('gulp-csso'); + const sourcemaps = require('gulp-sourcemaps'); + const atimport = require("postcss-import"); + const postcss = require("gulp-postcss"); + const autoprefixer = require('gulp-autoprefixer'); + const tailwindcss = require("tailwindcss"); + + return gulp .src(['assets/src/form.css']) .pipe(postcss([atimport(), tailwindcss(tailwindConfig)])) .pipe(autoprefixer({ @@ -52,20 +52,20 @@ gulp.task('form-css', function() { "last 1 version" ], cascade: false - })) + })) .pipe(csso()) .pipe(concat('form-build.min.css')) .pipe(gulp.dest("assets/dist/css/")); -}); + }); /** * Task: gulp form-js */ - gulp.task('form-js', function(){ - const sourcemaps = require('gulp-sourcemaps'); - const concat = require('gulp-concat'); + gulp.task('form-js', function () { + const sourcemaps = require('gulp-sourcemaps'); + const concat = require('gulp-concat'); - return gulp.src([ + return gulp.src([ 'assets/src/flatpickr/flatpickr.js', 'assets/src/select/select.js', 'assets/src/select-media/select-media.js', @@ -85,11 +85,11 @@ gulp.task('form-css', function() { /** * Task: gulp vendor-js */ - gulp.task('vendor-js', function(){ - const sourcemaps = require('gulp-sourcemaps'); - const concat = require('gulp-concat'); + gulp.task('vendor-js', function () { + const sourcemaps = require('gulp-sourcemaps'); + const concat = require('gulp-concat'); - return gulp.src([ + return gulp.src([ // Select2 'node_modules/select2/dist/js/select2.min.js', @@ -110,45 +110,49 @@ gulp.task('form-css', function() { /** * Task: gulp trumbowyg-fonts */ -gulp.task('trumbowyg-fonts', function(){ + gulp.task('trumbowyg-fonts', function () { return gulp.src(['node_modules/trumbowyg/dist/ui/icons.svg']) .pipe(gulp.dest('assets/dist/fonts/trumbowyg')); -}); + }); /** * Task: gulp trumbowyg-langs */ -gulp.task('trumbowyg-langs', function(){ + gulp.task('trumbowyg-langs', function () { return gulp.src(['node_modules/trumbowyg/dist/*langs/**/*']) .pipe(gulp.dest('assets/dist/lang/trumbowyg')); -}); + }); /** * Task: gulp flatpickr-langs */ -gulp.task('flatpickr-langs', function(){ + gulp.task('flatpickr-langs', function () { return gulp.src(['node_modules/flatpickr/dist/*l10n/**/*']) .pipe(gulp.dest('assets/dist/lang/flatpickr')); -}); + }); /** * Task: gulp default */ -gulp.task('default', - gulp.series( - 'trumbowyg-fonts', - 'trumbowyg-langs', - 'flatpickr-langs', - 'vendor-css', - 'form-css', - 'vendor-js', - 'form-js' -)); + gulp.task( + 'default', + gulp.series( + 'trumbowyg-fonts', + 'trumbowyg-langs', + 'flatpickr-langs', + 'vendor-css', + 'form-css', + 'vendor-js', + 'form-js' + ) + ); /** * Task: gulp watch */ -gulp.task('watch', function () { - gulp.watch(["fieldsets/**/*.html", "assets/src/"], - gulp.series('vendor-css', 'form-css')); -}); + gulp.task('watch', function () { + gulp.watch( + ["fieldsets/**/*.html", "assets/src/"], + gulp.series('vendor-css', 'form-css') + ); + }); diff --git a/package.json b/package.json index a5eed41..694893f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Form", - "version": "1.3.0", + "version": "1.4.0", "description": "Form Plugin to render user forms for Flextype.", "homepage": "https://flextype.org", "author": "Sergey Romanenko", diff --git a/plugin.yaml b/plugin.yaml index 0ab8f1e..133ea5f 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: Form -version: 1.2.1 +version: 1.4.0 description: Form Plugin to render user forms for Flextype. icon: fas fa-check-circle author: @@ -14,6 +14,6 @@ keywords: form, fieldsets license: MIT dependencies: - flextype: 0.9.9 + flextype: 0.9.10 twig: '>=1.0.0' jquery: '>=1.0.0' diff --git a/tailwind.config.js b/tailwind.config.js index 89f7940..85da8cc 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,47 +1,47 @@ module.exports = { - separator: ':', - theme: { - colors: { - black: '#000000', - white: '#ffffff', - dark: "#16171a", - "dark-muted": "#292b30", - red: '#E65354', - transparent: 'transparent', - gray: { - '000': '#f9f9f9', - '100': '#ededed', - '200': '#e1e1e1', - '300': '#d3d3d3', - '400': '#c4c4c4', - '500': '#b3b3b3', - '600': '#a0a0a0', - '700': '#898989', - '800': '#6c6c6c', - '900': '#3f3f3f', - }, - }, - opacity: { - '0': '0', - '25': '.25', - '50': '.5', - '75': '.75', - '10': '.1', - '20': '.2', - '30': '.3', - '40': '.4', - '50': '.5', - '60': '.6', - '70': '.7', - '80': '.8', - '90': '.9', - '100': '1' - }, - borderColor: theme => ({ - ...theme('colors'), - default: theme('colors.black', 'currentColor'), - }), - }, - variants: {}, - plugins: [], -} + separator: ':', + theme: { + colors: { + black: '#000000', + white: '#ffffff', + dark: "#16171a", + "dark-muted": "#292b30", + red: '#E65354', + transparent: 'transparent', + gray: { + '000': '#f9f9f9', + '100': '#ededed', + '200': '#e1e1e1', + '300': '#d3d3d3', + '400': '#c4c4c4', + '500': '#b3b3b3', + '600': '#a0a0a0', + '700': '#898989', + '800': '#6c6c6c', + '900': '#3f3f3f', + }, + }, + opacity: { + '0': '0', + '25': '.25', + '50': '.5', + '75': '.75', + '10': '.1', + '20': '.2', + '30': '.3', + '40': '.4', + '50': '.5', + '60': '.6', + '70': '.7', + '80': '.8', + '90': '.9', + '100': '1' + }, + borderColor: theme => ({ + ...theme('colors'), + default: theme('colors.black', 'currentColor'), + }), + }, + variants: {}, + plugins: [], + } diff --git a/twig/FormTwigExtension.php b/twig/FormTwigExtension.php index 27db6b4..53fd072 100644 --- a/twig/FormTwigExtension.php +++ b/twig/FormTwigExtension.php @@ -15,9 +15,9 @@ class FormTwigExtension extends AbstractExtension implements GlobalsInterface { /** - * Flextype Dependency Container + * Flextype Application */ - private $flextype; + protected $flextype; /** * Constructor @@ -41,9 +41,9 @@ public function getGlobals() : array class FormTwig { /** - * Flextype Dependency Container + * Flextype Application */ - private $flextype; + protected $flextype; /** * Constructor @@ -53,35 +53,23 @@ public function __construct($flextype) $this->flextype = $flextype; } - /** - * - */ public function render(array $fieldset, array $values = []) : string { - return $this->flextype['form']->render($fieldset, $values); + return $this->flextype->container('form')->render($fieldset, $values); } - /** - * - */ public function getElementID(string $element) : string { - return $this->flextype['form']->getElementID($element); + return $this->flextype->container('form')->getElementID($element); } - /** - * - */ public function getElementName(string $element) : string { - return $this->flextype['form']->getElementName($element); + return $this->flextype->container('form')->getElementName($element); } - /** - * - */ public function getElementValue(string $element, array $values, array $properties) { - return $this->flextype['form']->getElementValue($element, $values, $properties); + return $this->flextype->container('form')->getElementValue($element, $values, $properties); } }