From 22412adfc33b1eb8c1fcb51e7ece8b4293d58b8e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 2 Sep 2021 20:04:37 +0300 Subject: [PATCH 1/8] Fixed accidental admin plugin requirement for YAML filter in the form --- CHANGELOG.md | 8 ++++++++ blueprints.yaml | 2 +- templates/forms/default/field.html.twig | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e297f..75a62bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v5.1.1 +## mm/dd/2021 + +1. [](#new) + * Require **Grav 1.7.21** +1. [](#bugfix) + * Fixed accidental admin plugin requirement for YAML filter in the form + # v5.1.0 ## 08/31/2021 diff --git a/blueprints.yaml b/blueprints.yaml index ce35a6f..0804404 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -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 diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index 8e0f44e..9edfe94 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -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 %} From 25e9a4db470742baa5419fa4fccea373d479f620 Mon Sep 17 00:00:00 2001 From: Ryan Boog Date: Tue, 7 Sep 2021 12:28:51 -0500 Subject: [PATCH 2/8] Updating the display field to allow dynamic input (#529) This change will allow users to insert dynamically created contents inline on their forms. With this change, users can add something like this to their frontmatter on their fields within their pages: ``` content: '{{ page.content|raw }}' evaluate: true ``` This PR doesn't include doc changes. :( --- templates/forms/fields/display/display.html.twig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/forms/fields/display/display.html.twig b/templates/forms/fields/display/display.html.twig index 37d7382..bcb375a 100644 --- a/templates/forms/fields/display/display.html.twig +++ b/templates/forms/fields/display/display.html.twig @@ -1,5 +1,5 @@ {% extends "forms/field.html.twig" %} - + {% if field.file %} {% set content = read_file(field.file) %} {% else %} @@ -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 %} {% endblock %} From ff66b0748fde0c1746de1fce9d6cb19c539de067 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 8 Sep 2021 10:58:10 +0300 Subject: [PATCH 3/8] Fixed `GravForm.config` JS to have correct `current_url` and `current_params` settings --- CHANGELOG.md | 1 + templates/forms/default/form.html.twig | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a62bd..00b2bbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * 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 # v5.1.0 ## 08/31/2021 diff --git a/templates/forms/default/form.html.twig b/templates/forms/default/form.html.twig index 1db6b34..478d1f8 100644 --- a/templates/forms/default/form.html.twig +++ b/templates/forms/default/form.html.twig @@ -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 ~ " }; From 74ea1c4b89d5f730fd1f804edcacd18e89d86889 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 8 Sep 2021 11:59:20 +0300 Subject: [PATCH 4/8] Fixed custom file upload and remove routes --- CHANGELOG.md | 1 + classes/Form.php | 6 +++--- templates/forms/fields/file/file.html.twig | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b2bbc..900902d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ 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 # v5.1.0 ## 08/31/2021 diff --git a/classes/Form.php b/classes/Form.php index 4bbbc36..a11e185 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -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'); diff --git a/templates/forms/fields/file/file.html.twig b/templates/forms/fields/file/file.html.twig index 9f6094f..f1d5f77 100644 --- a/templates/forms/fields/file/file.html.twig +++ b/templates/forms/fields/file/file.html.twig @@ -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 %} -
+ {% set file_url_add = form.getFileUploadAjaxRoute() %} + {% set file_url_remove = form.getFileDeleteAjaxRoute(null, null) %} +
{% block file_extras %}{% endblock %} Date: Wed, 8 Sep 2021 14:20:26 +0300 Subject: [PATCH 5/8] Fixed bug where uploading file has no effect [#349] --- CHANGELOG.md | 1 + form.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 900902d..13c5495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * 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) # v5.1.0 ## 08/31/2021 diff --git a/form.php b/form.php index 8367d85..5344802 100644 --- a/form.php +++ b/form.php @@ -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) { @@ -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; @@ -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) { From f516594037bf98f1bd80268f5631acb511368c18 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 14 Sep 2021 10:40:55 +0300 Subject: [PATCH 6/8] Fixed field with numeric field name in `prepare_form_fields()` [#530] --- CHANGELOG.md | 1 + classes/TwigExtension.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c5495..6c1c9ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * 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 diff --git a/classes/TwigExtension.php b/classes/TwigExtension.php index 8366bb0..1556f0d 100644 --- a/classes/TwigExtension.php +++ b/classes/TwigExtension.php @@ -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 = $field['name'] ?? (string)$name; } // Make sure that the field has a name. From 716344191f7dc63b72925514d3530e66caa3641e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 14 Sep 2021 11:55:10 +0300 Subject: [PATCH 7/8] Further fix to `prepare_form_fields()` [#530] --- classes/TwigExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/TwigExtension.php b/classes/TwigExtension.php index 1556f0d..4cae01b 100644 --- a/classes/TwigExtension.php +++ b/classes/TwigExtension.php @@ -78,7 +78,7 @@ 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)) { // Look at the field.name and if not set, fall back to the key. - $name = $field['name'] ?? (string)$name; + $name = (string)($field['name'] ?? $name); } // Make sure that the field has a name. From 0efe200870054f213cd40f3ba95954f5de4f02e6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Sep 2021 12:53:10 -0600 Subject: [PATCH 8/8] prepare for release --- CHANGELOG.md | 2 +- blueprints.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c1c9ee..88e1916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v5.1.1 -## mm/dd/2021 +## 09/14/2021 1. [](#new) * Require **Grav 1.7.21** diff --git a/blueprints.yaml b/blueprints.yaml index 0804404..6f11ae7 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -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: