Upgrade to 3.2.0

This commit is contained in:
Bastian Allgeier
2019-06-25 09:56:08 +02:00
parent 9e18cf635d
commit 9c89153d35
296 changed files with 14408 additions and 2504 deletions

View File

@@ -3,9 +3,9 @@
namespace Kirby\Form;
use Exception;
use Kirby\Data\Yaml;
use Kirby\Cms\App;
use Kirby\Cms\Model;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Http\Router;
use Kirby\Toolkit\Component;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\V;
@@ -14,6 +14,12 @@ use Kirby\Toolkit\V;
* Form Field object that takes a Vue component style
* array of properties and methods and converts them
* to a usable field option array for the API.
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class Field extends Component
{
@@ -54,6 +60,9 @@ class Field extends Component
$this->validate();
}
/**
* @return mixed
*/
public function api()
{
if (isset($this->options['api']) === true && is_callable($this->options['api']) === true) {
@@ -61,6 +70,9 @@ class Field extends Component
}
}
/**
* @return mixed
*/
public function data($default = false)
{
$save = $this->options['save'] ?? true;
@@ -103,13 +115,13 @@ class Field extends Component
return I18n::translate($before, $before);
},
/**
* Default value for the field, which will be used when a Page/File/User is created
* Default value for the field, which will be used when a page/file/user is created
*/
'default' => function ($default = null) {
return $default;
},
/**
* If true, the field is no longer editable and will not be saved
* If `true`, the field is no longer editable and will not be saved
*/
'disabled' => function (bool $disabled = null): bool {
return $disabled ?? false;
@@ -139,13 +151,13 @@ class Field extends Component
return I18n::translate($placeholder, $placeholder);
},
/**
* If true, the field has to be filled in correctly to be saved.
* If `true`, the field has to be filled in correctly to be saved.
*/
'required' => function (bool $required = null): bool {
return $required ?? false;
},
/**
* If false, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.
* If `false`, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.
*/
'translate' => function (bool $translate = true): bool {
return $translate;
@@ -157,7 +169,7 @@ class Field extends Component
return $when;
},
/**
* The width of the field in the field grid. Available widths: 1/1, 1/2, 1/3, 1/4, 2/3, 3/4
* The width of the field in the field grid. Available widths: `1/1`, `1/2`, `1/3`, `1/4`, `2/3`, `3/4`
*/
'width' => function (string $width = '1/1') {
return $width;
@@ -204,6 +216,9 @@ class Field extends Component
return empty($this->errors) === true;
}
/**
* @return Kirby\Cms\App
*/
public function kirby()
{
return $this->model->kirby();
@@ -236,7 +251,7 @@ class Field extends Component
});
}
protected function validate()
protected function validate(): void
{
$validations = $this->options['validations'] ?? [];
$this->errors = [];

View File

@@ -3,11 +3,16 @@
namespace Kirby\Form;
use Closure;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\Collection;
/**
* A collection of Field objects
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class Fields extends Collection
{

View File

@@ -3,7 +3,6 @@
namespace Kirby\Form;
use Throwable;
use Kirby\Toolkit\Collection;
use Kirby\Data\Yaml;
/**
@@ -11,6 +10,12 @@ use Kirby\Data\Yaml;
* used to create a list of form fields
* and handles global form validation
* and submission
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class Form
{
@@ -154,7 +159,7 @@ class Form
return $strings;
}
public function toArray()
public function toArray(): array
{
$array = [
'errors' => $this->errors(),

View File

@@ -3,20 +3,19 @@
namespace Kirby\Form;
use Kirby\Cms\App;
use Kirby\Cms\File;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Cms\StructureObject;
use Kirby\Cms\User;
use Kirby\Toolkit\A;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Obj;
/**
* Foundation for the Options query
* classes, that are used to generate
* options arrays for select fields,
* radio boxes, checkboxes and more.
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class Options
{

View File

@@ -3,9 +3,7 @@
namespace Kirby\Form;
use Kirby\Cms\Nest;
use Kirby\Cms\Structure;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\LogicException;
use Kirby\Toolkit\Query;
use Kirby\Toolkit\Properties;
use Kirby\Toolkit\Str;
@@ -13,6 +11,12 @@ use Kirby\Toolkit\Str;
/**
* The OptionsApi class handles fetching options
* from any REST API with valid JSON data.
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class OptionsApi
{

View File

@@ -16,6 +16,12 @@ use Kirby\Toolkit\Str;
* of data. In case of Kirby, you can query
* pages, files, users or structures to create
* options out of them.
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class OptionsQuery
{

View File

@@ -7,6 +7,12 @@ use Kirby\Toolkit\V;
/**
* Often used validation rules for fields
*
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class Validations
{
@@ -131,7 +137,7 @@ class Validations
{
if ($field->isEmpty($value) === false) {
$values = array_column($field->options(), 'value');
foreach ($value as $key => $val) {
foreach ($value as $val) {
if (in_array($val, $values, true) === false) {
throw new InvalidArgumentException([
'key' => 'validation.option'