Skip to content

Commit

Permalink
Form 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 19, 2020
1 parent 9cda8f3 commit b2de59e
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 186 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.4.0"></a>
# [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

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

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.9-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.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>
</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.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) |

Expand Down Expand Up @@ -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('./');
Expand Down
25 changes: 13 additions & 12 deletions app/Models/Fieldsets.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@

namespace Flextype\Plugin\Form\Models;

use Flextype\App\Foundation\Container;
use Flextype\Component\Filesystem\Filesystem;
use function count;
use function rename;

class Fieldsets
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -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'));
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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'];
}
}
Expand All @@ -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;
}

/**
Expand All @@ -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;
Expand All @@ -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;
Expand Down
40 changes: 25 additions & 15 deletions app/Models/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,47 @@

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
*
* @access public
*/
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,
]
);
}

/**
Expand All @@ -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 = '';
Expand Down
2 changes: 1 addition & 1 deletion assets/src/select-tags/select-tags.js
Original file line number Diff line number Diff line change
@@ -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());
});
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
85 changes: 52 additions & 33 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,95 @@

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 {
$trumbowyg_locale_js = '';
$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',
])
);
}
Loading

0 comments on commit b2de59e

Please sign in to comment.