Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR: use array casting and arguments spread #950

Merged
merged 1 commit into from
Feb 17, 2020
Merged
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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if $field===null? But ok, in this case it would be very uncommon to use `null value :)

}

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