From 909f9227612f66d05ef207e2274118c0425be457 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 25 Aug 2020 16:00:49 +0300 Subject: [PATCH] Form 1.5.0 --- CHANGELOG.md | 7 +++++++ README.md | 8 ++++---- app/Models/Fieldsets.php | 17 ++++++----------- app/Models/Form.php | 11 +++-------- dependencies.php | 38 +++++++++++++++++++------------------- package.json | 2 +- plugin.yaml | 4 ++-- twig/FormTwigExtension.php | 25 ++++++++++--------------- 8 files changed, 52 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a164a5d..3bd3068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.5.0](https://github.com/flextype-plugins/form/compare/v1.4.0...v1.5.0) (2020-08-25) + +### Features + +* **core** update code base for new Flextype 0.9.11 + # [1.4.0](https://github.com/flextype-plugins/form/compare/v1.3.0...v1.4.0) (2020-08-19) diff --git a/README.md b/README.md index 8131b8e..2e87eca 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.10 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [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; -$flextype->post('{uri:.+}', function(Request $request, Response $response) use ($flextype) { +flextype()->post('{uri:.+}', function(Request $request, Response $response) { // get post data $post_data = $request->getParsedBody(); // save date from $post_data - $flextype->container()['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 fe70744..2573025 100644 --- a/app/Models/Fieldsets.php +++ b/app/Models/Fieldsets.php @@ -15,19 +15,14 @@ class Fieldsets { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + if (! Filesystem::has($this->getDirLocation())) { Filesystem::createDir($this->getDirLocation()); @@ -55,7 +50,7 @@ public function fetch(string $id) if (Filesystem::has($fieldset_file)) { if ($fieldset_body = Filesystem::read($fieldset_file)) { - if ($fieldset_decoded = $this->flextype->container('yaml')->decode($fieldset_body)) { + if ($fieldset_decoded = flextype('yaml')->decode($fieldset_body)) { return $fieldset_decoded; } @@ -90,7 +85,7 @@ public function fetchAll() : array continue; } - $fieldset_content = $this->flextype->container('yaml')->decode(Filesystem::read($fieldset['path'])); + $fieldset_content = flextype('yaml')->decode(Filesystem::read($fieldset['path'])); $fieldsets[$fieldset['basename']] = $fieldset_content['title']; } } @@ -133,7 +128,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->container('yaml')->encode($data)); + return Filesystem::write($fieldset_file, flextype('yaml')->encode($data)); } return false; @@ -154,7 +149,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->container('yaml')->encode($data)); + return Filesystem::write($fieldset_file, flextype('yaml')->encode($data)); } return false; diff --git a/app/Models/Form.php b/app/Models/Form.php index e18d1e6..e6a1da3 100644 --- a/app/Models/Form.php +++ b/app/Models/Form.php @@ -19,17 +19,12 @@ class Form { - /** - * Flextype Application - */ - protected $flextype; - /** * __construct */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -44,7 +39,7 @@ public function __construct($flextype) */ public function render(array $fieldset, array $values = []) : string { - return $this->flextype->container('twig')->fetch( + return flextype('twig')->fetch( 'plugins/form/fieldsets/base.html', [ 'fieldset' => $fieldset, diff --git a/dependencies.php b/dependencies.php index 554d6c1..1a736e3 100644 --- a/dependencies.php +++ b/dependencies.php @@ -21,30 +21,30 @@ /** * Add Form Model to Flextype container */ -$flextype->container()['form'] = static function () use ($flextype) { - return new Form($flextype); +flextype()->container()['form'] = static function () { + return new Form(); }; /** * Add Fieldsets Model to Flextype container */ -$flextype->container()['fieldsets'] = static function () use ($flextype) { - return new Fieldsets($flextype); +flextype()->container()['fieldsets'] = static function () { + return new Fieldsets(); }; /** * Add Form Twig extension */ -$flextype->container('twig')->addExtension(new FormTwigExtension($flextype)); +flextype('twig')->addExtension(new FormTwigExtension()); /** * Add Assets */ -$_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') : []; +$_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') : []; -if ($flextype->container('registry')->get('plugins.form.settings.load_on_admin')) { - $flextype->container('registry')->set( +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', @@ -53,8 +53,8 @@ ); } -if ($flextype->container('registry')->get('plugins.form.settings.load_on_site')) { - $flextype->container('registry')->set( +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', @@ -63,10 +63,10 @@ ); } -if ($flextype->container('registry')->get('flextype.settings.locale') === 'en_US') { +if (flextype('registry')->get('flextype.settings.locale') === 'en_US') { $_locale = 'en'; } else { - $_locale = substr(strtolower($flextype->container('registry')->get('flextype.settings.locale')), 0, 2); + $_locale = substr(strtolower(flextype('registry')->get('flextype.settings.locale')), 0, 2); } if ($_locale !== 'en') { @@ -77,11 +77,11 @@ $flatpickr_locale_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') : []; +$_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') : []; -if ($flextype->container('registry')->get('plugins.form.settings.load_on_admin')) { - $flextype->container('registry')->set( +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', @@ -92,8 +92,8 @@ ); } -if ($flextype->container('registry')->get('plugins.form.settings.load_on_site')) { - $flextype->container('registry')->set( +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', diff --git a/package.json b/package.json index 694893f..8b394d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Form", - "version": "1.4.0", + "version": "1.5.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 133ea5f..389febc 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: Form -version: 1.4.0 +version: 1.5.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.10 + flextype: 0.9.11 twig: '>=1.0.0' jquery: '>=1.0.0' diff --git a/twig/FormTwigExtension.php b/twig/FormTwigExtension.php index 53fd072..eb58256 100644 --- a/twig/FormTwigExtension.php +++ b/twig/FormTwigExtension.php @@ -14,17 +14,12 @@ class FormTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -33,7 +28,7 @@ public function __construct($flextype) public function getGlobals() : array { return [ - 'form' => new FormTwig($this->flextype), + 'form' => new FormTwig(), ]; } } @@ -43,33 +38,33 @@ class FormTwig /** * Flextype Application */ - protected $flextype; + /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } public function render(array $fieldset, array $values = []) : string { - return $this->flextype->container('form')->render($fieldset, $values); + return flextype('form')->render($fieldset, $values); } public function getElementID(string $element) : string { - return $this->flextype->container('form')->getElementID($element); + return flextype('form')->getElementID($element); } public function getElementName(string $element) : string { - return $this->flextype->container('form')->getElementName($element); + return flextype('form')->getElementName($element); } public function getElementValue(string $element, array $values, array $properties) { - return $this->flextype->container('form')->getElementValue($element, $values, $properties); + return flextype('form')->getElementValue($element, $values, $properties); } }