Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3', '8.4']
kirby-versions: ['^3.5', '^4.0', '5.0.0-rc.1']
exclude:
- kirby-versions: '^3.5'
php-versions: '8.4'
- kirby-versions: '5.0.0-rc.1'
php-versions: '8.1'
php-versions: ['8.3', '8.4', '8.5']
kirby-versions: ['^6.0@beta']

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

A versatile [Kirby](http://getkirby.com) plugin to handle web form actions.

[![Documentation Status](https://readthedocs.org/projects/kirby-uniform/badge/?version=latest)](https://kirby-uniform.readthedocs.io/en/latest/?badge=latest) [![Tests](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml/badge.svg)](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml) ![Kirby >=3](https://img.shields.io/badge/Kirby-%3E=3-green.svg)
[![Documentation Status](https://readthedocs.org/projects/kirby-uniform/badge/?version=latest)](https://kirby-uniform.readthedocs.io/en/latest/?badge=latest) [![Tests](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml/badge.svg)](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml) ![Kirby 6](https://img.shields.io/badge/Kirby-6-green.svg)

This is Uniform for Kirby >=3. You can find Uniform for Kirby 2 in the [kirby-2 branch](https://github.com/mzur/kirby-uniform/tree/kirby-2).
This is Uniform for Kirby 6. Use Uniform v5 for Kirby 3 to 5. You can find Uniform for Kirby 2 in the [kirby-2 branch](https://github.com/mzur/kirby-uniform/tree/kirby-2).

Builtin actions:

- [Email](https://kirby-uniform.readthedocs.io/en/latest/actions/email/): Send the form data by email.
- [EmailSelect](https://kirby-uniform.readthedocs.io/en/latest/actions/email-select/): Choose from multiple recipients to send the form data by email.
- [Log](https://kirby-uniform.readthedocs.io/en/latest/actions/log/): Log the form data to a file.
- [Login](https://kirby-uniform.readthedocs.io/en/latest/actions/login/): Log in to the Kirby frontend.
- [SessionStore](https://kirby-uniform.readthedocs.io/en/latest/actions/session-store): Store the form in the user's session.
- [SessionStore](https://kirby-uniform.readthedocs.io/en/latest/actions/session-store): Store the form data in the user's session.
- [Upload](https://kirby-uniform.readthedocs.io/en/latest/actions/upload): Handle file uploads.
- [Webhook](https://kirby-uniform.readthedocs.io/en/latest/actions/webhook/): Send the form data as an HTTP request to a webhook.

Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"docs": "http://kirby-uniform.readthedocs.io"
},
"require": {
"php": "^8.3",
"mzur/kirby-form": "^3.0",
"getkirby/composer-installer": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"getkirby/cms": "^3.5 || ^4.0 || 5.0.0-rc.1"
"getkirby/cms": "^6.0@beta"
},
"autoload": {
"psr-4": {
Expand All @@ -36,6 +37,11 @@
"Uniform\\Tests\\": "tests/"
}
},
"extra": {
"kirby": {
"compatible": "^6.0"
}
},
"config": {
"optimize-autoloader": true,
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Name of a email template to use as email body. If this option is set, the action
Check out the email templates of the [Uniform repo](https://github.com/mzur/kirby-uniform/tree/master/templates/emails) for examples.

!!! warning "Note"
You cannot access form fields with the name `_data` or `_options` directly in the template as these are reserved for the additional variables provided by Uniform. Use `$_data['_data']` and `$_data['_options']` in this case.
You cannot access form fields with the name `_data` or `_options` directly in the template as these are reserved for the additional variables provided by Uniform. Use `$_data['_data']` and `$_data['_options']` in this case. Form fields with the name `slot` or `slots` cannot be used with templates at all, as Kirby reserves these variable names in templates.

### body

Expand Down
6 changes: 3 additions & 3 deletions docs/actions/session-store.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SessionStore Action

This action stores the form in the user's session object so that it can be accessed in subsequent requests - e.g. after a redirect.
This action stores the form data in the user's session so that it can be accessed in subsequent requests - e.g. after a redirect.

## Example

Expand Down Expand Up @@ -48,8 +48,8 @@ return function ($kirby)
### Confirmation Page Template

```html+php
<?php if (kirby()->session()->get('user-form')): ?>
Thank you <?php echo kirby()->session()->get('user-form')->data('email'); ?> for subscribing.
<?php if ($data = kirby()->session()->get('user-form')): ?>
Thank you <?php echo $data['email']; ?> for subscribing.
<?php endif; ?>
```

Expand Down
11 changes: 11 additions & 0 deletions docs/upgrade-guide-v5-v6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Upgrade Guide v5->v6

Uniform v6 requires Kirby 6 and PHP 8.3 or newer. There are only the following breaking changes between Uniform v5 and v6:

- The [SessionStore action](actions/session-store) now stores the form data as an array instead of the form, because Kirby 6 does not restore objects from the session. Replace `kirby()->session()->get('user-form')->data('email')` with `kirby()->session()->get('user-form')['email']`.

- Custom [email templates](actions/email#template) that loop over `$data` to print all form fields have to loop over `$_data` instead. In Kirby 6, `$data` also contains the global template variables of Kirby.

- Form fields with the name `slot` or `slots` cannot be used with email templates, as Kirby 6 reserves these variable names in templates.

That's it!
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ nav:
- AJAX: examples/ajax.md
- Dynamic Fields: examples/dynamic.md
- Answers: answers.md
- 'Upgrade Guide v5->v6': upgrade-guide-v5-v6.md
- 'Upgrade Guide v4->v5': upgrade-guide-v4-v5.md
- 'Upgrade Guide v3->v4': upgrade-guide-v3-v4.md
theme: readthedocs
Expand Down
20 changes: 5 additions & 15 deletions src/Actions/EmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,7 @@ protected function resolveTemplate($string) {
return is_scalar($item);
});

$version = explode('.', App::version());
$majorVersion = intval($version[0]);
$minorVersion = intval($version[1]);
$fallback = ['fallback' => ''];

// The arguments to Str::template changed in Kirby 3.6.
if ($majorVersion <= 3 && $minorVersion <= 5) {
$fallback = '';
}

return Str::template($string, $templatableItems, $fallback);
return Str::template($string, $templatableItems, ['fallback' => '']);
}

/**
Expand Down Expand Up @@ -191,10 +181,10 @@ private function preset(string|null $preset): array
}

if (($presetOptions = App::instance()->option('email.presets.' . $preset)) === null) {
throw new NotFoundException([
'key' => 'email.preset.notFound',
'data' => ['name' => $preset],
]);
throw new NotFoundException(
key: 'email.preset.notFound',
data: ['name' => $preset],
);
}

// Options passed to the action always superseed preset options
Expand Down
4 changes: 2 additions & 2 deletions src/Actions/SessionStoreAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function perform()
// get the name of the session variable
$name = $this->option('name', 'session-store');

// put form into session
App::instance()->session()->set($name, $this->form);
// put form data into session
App::instance()->session()->set($name, $this->form->data());
}
}
2 changes: 1 addition & 1 deletion templates/emails/default.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

foreach ($data as $field => $value) {
foreach ($_data as $field => $value) {
if (in_array($field, ['_data', '_options'])) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/emails/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</thead>
<tbody>
<?php
foreach ($data as $field => $value):
foreach ($_data as $field => $value):
if (in_array($field, ['_data', '_options'])) {
continue;
}
Expand Down
10 changes: 4 additions & 6 deletions tests/Actions/SessionStoreActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public function testPerform()
$this->assertEmpty($session->get('session-store'));

$action->perform();
$form = $session->get('session-store');
$data = $session->get('session-store');

$this->assertInstanceOf(Form::class, $form);
$this->assertEquals('my message', $form->data('message'));
$this->assertEquals(['message' => 'my message'], $data);
}

public function testPerformWithName()
Expand All @@ -40,9 +39,8 @@ public function testPerformWithName()
$this->assertEmpty($session->get('my-session-store'));

$action->perform();
$form = $session->get('my-session-store');
$data = $session->get('my-session-store');

$this->assertInstanceOf(Form::class, $form);
$this->assertEquals('my message', $form->data('message'));
$this->assertEquals(['message' => 'my message'], $data);
}
}
Loading