3.4.0
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Kirby\Form;
|
||||
use Exception;
|
||||
use Kirby\Cms\Model;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Component;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\V;
|
||||
@@ -324,8 +325,12 @@ class Field extends Component
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->validate) === false) {
|
||||
$errors = V::errors($this->value(), $this->validate);
|
||||
if (
|
||||
empty($this->validate) === false &&
|
||||
($this->isEmpty() === false || $this->isRequired() === true)
|
||||
) {
|
||||
$rules = A::wrap($this->validate);
|
||||
$errors = V::errors($this->value(), $rules);
|
||||
|
||||
if (empty($errors) === false) {
|
||||
$this->errors = array_merge($this->errors, $errors);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Kirby\Form;
|
||||
|
||||
use Kirby\Data\Yaml;
|
||||
use Kirby\Data\Data;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@@ -154,7 +154,7 @@ class Form
|
||||
if ($value === null) {
|
||||
$strings[$key] = null;
|
||||
} elseif (is_array($value) === true) {
|
||||
$strings[$key] = Yaml::encode($value);
|
||||
$strings[$key] = Data::encode($value, 'yaml');
|
||||
} else {
|
||||
$strings[$key] = $value;
|
||||
}
|
||||
|
@@ -3,7 +3,10 @@
|
||||
namespace Kirby\Form;
|
||||
|
||||
use Kirby\Cms\Nest;
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Http\Remote;
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\Properties;
|
||||
use Kirby\Toolkit\Query;
|
||||
use Kirby\Toolkit\Str;
|
||||
@@ -56,14 +59,31 @@ class OptionsApi
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
$content = @file_get_contents($this->url());
|
||||
if (Url::isAbsolute($this->url()) === true) {
|
||||
// URL, request via cURL
|
||||
$data = Remote::get($this->url())->json();
|
||||
} else {
|
||||
// local file, get contents locally
|
||||
|
||||
if (empty($content) === true) {
|
||||
return [];
|
||||
// ensure the file exists before trying to load it as the
|
||||
// file_get_contents() warnings need to be suppressed
|
||||
if (is_file($this->url()) !== true) {
|
||||
throw new Exception('Local file ' . $this->url() . ' was not found');
|
||||
}
|
||||
|
||||
$content = @file_get_contents($this->url());
|
||||
|
||||
if (is_string($content) !== true) {
|
||||
throw new Exception('Unexpected read error'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (empty($content) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = json_decode($content, true);
|
||||
}
|
||||
|
||||
$data = json_decode($content, true);
|
||||
|
||||
if (is_array($data) === false) {
|
||||
throw new InvalidArgumentException('Invalid options format');
|
||||
}
|
||||
|
Reference in New Issue
Block a user