Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 25, 2020
2 parents b2de59e + 909f922 commit f29c185
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 60 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.5.0"></a>
# [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

<a name="1.4.0"></a>
# [1.4.0](https://github.com/flextype-plugins/form/compare/v1.3.0...v1.4.0) (2020-08-19)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Form Plugin for <a href="https://flextype.org/">Flextype</a></h1>

<p align="center">
<a href="https://github.com/flextype-plugins/form/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/form.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/form"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/form"><img src="https://img.shields.io/github/downloads/flextype-plugins/form/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.10-green.svg?color=black" alt="Flextype"></a> <a href="https://scrutinizer-ci.com/g/flextype-plugins/form?branch=dev&color=black"><img src="https://img.shields.io/scrutinizer/g/flextype-plugins/form.svg?branch=dev" alt="Quality Score"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
<a href="https://github.com/flextype-plugins/form/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/form.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/form"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/form"><img src="https://img.shields.io/github/downloads/flextype-plugins/form/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.11-green.svg?color=black" alt="Flextype"></a> <a href="https://scrutinizer-ci.com/g/flextype-plugins/form?branch=dev&color=black"><img src="https://img.shields.io/scrutinizer/g/flextype-plugins/form.svg?branch=dev" alt="Quality Score"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
</p>

Form Plugin to render user forms for Flextype.
Expand All @@ -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) |

Expand Down Expand Up @@ -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('./');
Expand Down
17 changes: 6 additions & 11 deletions app/Models/Fieldsets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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'];
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions app/Models/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@

class Form
{
/**
* Flextype Application
*/
protected $flextype;

/**
* __construct
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand All @@ -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,
Expand Down
38 changes: 19 additions & 19 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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') {
Expand All @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'
25 changes: 10 additions & 15 deletions twig/FormTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

/**
Expand All @@ -33,7 +28,7 @@ public function __construct($flextype)
public function getGlobals() : array
{
return [
'form' => new FormTwig($this->flextype),
'form' => new FormTwig(),
];
}
}
Expand All @@ -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);
}
}

0 comments on commit f29c185

Please sign in to comment.