Skip to content

Commit

Permalink
Merge branch 'release/5.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Sep 14, 2021
2 parents 5b9ce04 + 0efe200 commit 5e806d1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 19 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v5.1.1
## 09/14/2021

1. [](#new)
* Require **Grav 1.7.21**
1. [](#bugfix)
* Fixed accidental admin plugin requirement for YAML filter in the form
* Fixed `GravForm.config` JS to have correct `current_url` and `current_params` settings
* Fixed custom file upload and remove routes
* Fixed bug where uploading file has no effect [#349](https://github.com/getgrav/grav-plugin-form/issues/349)
* Fixed field with numeric field name in `prepare_form_fields()` [#530](https://github.com/getgrav/grav-plugin-form/issues/530)

# v5.1.0
## 08/31/2021

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Form
slug: form
type: plugin
version: 5.1.0
version: 5.1.1
description: Enables the forms handling
icon: check-square
author:
Expand All @@ -14,7 +14,7 @@ bugs: https://github.com/getgrav/grav-plugin-form/issues
license: MIT

dependencies:
- { name: grav, version: '>=1.7.19' }
- { name: grav, version: '>=1.7.21' }

form:
validation: strict
Expand Down
6 changes: 3 additions & 3 deletions classes/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,11 @@ public function getFileUploadAjaxRoute(): ?Route
}

/**
* @param string $field
* @param string $filename
* @param string|null $field
* @param string|null $filename
* @return Route|null
*/
public function getFileDeleteAjaxRoute($field, $filename): ?Route
public function getFileDeleteAjaxRoute($field = null, $filename = null): ?Route
{
$route = Uri::getCurrentRoute()->withExtension('json')->withGravParam('task', 'file-remove');

Expand Down
3 changes: 2 additions & 1 deletion classes/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function prepareFormField($field, $name = null, $parent = null, array $op

// Check if we have just a list of fields (no name given).
if (is_int($name)) {
$name = null;
// Look at the field.name and if not set, fall back to the key.
$name = (string)($field['name'] ?? $name);
}

// Make sure that the field has a name.
Expand Down
17 changes: 10 additions & 7 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,10 @@ protected function getCurrentPageRoute()
* Retrieve a form based on the form name
*
* @param string $form_name
* @param string $unique_id
* @return mixed
*/
protected function getFormByName($form_name)
protected function getFormByName($form_name, $unique_id = '')
{
$form = $this->active_forms[$form_name] ?? null;
if (!$form) {
Expand All @@ -931,9 +932,11 @@ protected function getFormByName($form_name)
return null;
}

// Reset form to change the cached unique id and to fire onFormInitialized event.
$form->setUniqueId('');
$form->reset();
if ('' === $unique_id) {
// Reset form to change the cached unique id and to fire onFormInitialized event.
$form->setUniqueId('');
$form->reset();
}

// Register form to the active forms to get the same instance back next time.
$this->active_forms[$form_name] = $form;
Expand Down Expand Up @@ -1025,14 +1028,14 @@ protected function form(PageInterface $page = null)
}

// Try to find the posted form if available.
$form_name = $this->grav['uri']->post('__form-name__', FILTER_SANITIZE_STRING);
$unique_id = $this->grav['uri']->post('__unique_form_id__', FILTER_SANITIZE_STRING);
$form_name = $this->grav['uri']->post('__form-name__', FILTER_SANITIZE_STRING) ?? '';
$unique_id = $this->grav['uri']->post('__unique_form_id__', FILTER_SANITIZE_STRING) ?? '';

if (!$form_name) {
$form_name = $page ? $page->slug() : null;
}

$form = $this->getFormByName($form_name);
$form = $this->getFormByName($form_name, $unique_id);

// last attempt using current page's form
if (!$form && $page) {
Expand Down
2 changes: 1 addition & 1 deletion templates/forms/default/field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% endif %}

{% if (field.yaml or field.validate.type == 'yaml') and value is iterable %}
{% set value = value|toYaml %}
{% set value = value|yaml %}
{% endif %}
{% else %}
{% set toggleable = false %}
Expand Down
5 changes: 3 additions & 2 deletions templates/forms/default/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
{% do assets.addInlineJs("
window.GravForm = window.GravForm || {};
window.GravForm.config = {
current_url: '" ~ uri.route(true) ~"',
current_url: '" ~ grav.route.withoutParams() ~"',
current_params: " ~ grav.route.params|json_encode ~ ",
param_sep: '" ~ config.system.param_sep ~ "',
base_url_relative: '" ~ base_url_relative ~ "',
param_sep: '"~ config.system.param_sep ~ "',
form_nonce: '" ~ form.getNonce() ~ "',
session_timeout: " ~ config.system.session.timeout ~ "
};
Expand Down
8 changes: 6 additions & 2 deletions templates/forms/fields/display/display.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "forms/field.html.twig" %}

{% if field.file %}
{% set content = read_file(field.file) %}
{% else %}
Expand All @@ -11,7 +11,11 @@
{% if field.markdown %}
{{ content|t|markdown|raw }}
{% else %}
{{ content|t|raw }}
{% if field.evaluate %}
{{ evaluate_twig(content)|raw }}
{% else %}
{{ content|t|raw }}
{% endif %}
{% endif %}
</div>
{% endblock %}
8 changes: 7 additions & 1 deletion templates/forms/fields/file/file.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@
{% block prepend %}{% endblock %}
{% set settings = {name: field.name, paramName: (scope ~ field.name)|fieldName ~ (files.multiple ? '[]' : ''), limit: limit, filesize: max_filesize, accept: files.accept, resolution: files.resolution, resizeWidth: files.resizeWidth, resizeHeight: files.resizeHeight, resizeQuality: files.resizeQuality } %}
{% set dropzoneSettings = field.dropzone %}
<div class="{{ form_field_wrapper_classes ?: 'form-input-wrapper' }} {{ field.classes }} dropzone files-upload form-input-file {{ field.size }}" data-grav-file-settings="{{ settings|json_encode|e('html_attr') }}" data-dropzone-options="{{ dropzoneSettings|json_encode|e('html_attr') }}" {% if form.getFileUploadAjaxRoute %}data-file-url-add="{{ form.getFileUploadAjaxRoute() }}"{% endif %}>
{% set file_url_add = form.getFileUploadAjaxRoute() %}
{% set file_url_remove = form.getFileDeleteAjaxRoute(null, null) %}
<div class="{{ form_field_wrapper_classes ?: 'form-input-wrapper' }} {{ field.classes }} dropzone files-upload form-input-file {{ field.size }}"
data-grav-file-settings="{{ settings|json_encode|e('html_attr') }}"
data-dropzone-options="{{ dropzoneSettings|json_encode|e('html_attr') }}"
{% if file_url_add %}data-file-url-add="{{ file_url_add|e('html_attr') }}"{% endif %}
{% if file_url_remove %}data-file-url-remove="{{ file_url_remove|e('html_attr') }}"{% endif %}>
{% block file_extras %}{% endblock %}
<input
{# required attribute structures #}
Expand Down

0 comments on commit 5e806d1

Please sign in to comment.