Skip to content

Commit

Permalink
use array casting and arguments spread (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov authored Feb 17, 2020
1 parent f5c4caa commit 12351d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
14 changes: 5 additions & 9 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,7 @@ public function addField($name, $decorator = null, $field = null)
public function addFields($fields)
{
foreach ($fields as $field) {
if (is_array($field)) {
$this->addField(...$field);
} else {
$this->addField($field);
}
$this->addField(...(array) $field);
}

return $this;
Expand Down Expand Up @@ -474,8 +470,8 @@ public function decoratorFactory(\atk4\data\Field $f, $seed = [])

$seed = $this->mergeSeeds(
$seed,
isset($f->ui['form']) ? $f->ui['form'] : null,
isset($this->typeToDecorator[$f->type]) ? $this->typeToDecorator[$f->type] : null,
$f->ui['form'] ?? null,
$this->typeToDecorator[$f->type] ?? null,
$fallback_seed
);

Expand Down Expand Up @@ -517,10 +513,10 @@ public function loadPOST()

foreach ($this->fields as $key => $field) {
try {
$value = isset($post[$key]) ? $post[$key] : null;

// save field value only if field was editable in form at all
if (!$field->readonly && !$field->disabled) {
$value = $post[$key] ?? null;

$this->model[$key] = $this->app->ui_persistence->typecastLoadField($field->field, $value);
}
} catch (\atk4\core\Exception $e) {
Expand Down
6 changes: 1 addition & 5 deletions src/FormLayout/_Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ protected function _addField($decorator, $field)
public function addFields($fields)
{
foreach ($fields as $field) {
if (is_array($field)) {
$this->addField(...$field);
} else {
$this->addField($field);
}
$this->addField(...(array) $field);
}

return $this;
Expand Down

0 comments on commit 12351d6

Please sign in to comment.