diff --git a/src/Table.php b/src/Table.php index 08289ad8eb..a7c564f668 100644 --- a/src/Table.php +++ b/src/Table.php @@ -207,11 +207,8 @@ public function addColumn($name, $columnDecorator = null, $field = null) $field = null; } elseif (!$existingField) { // Add missing field - if ($field) { - $field = $this->model->addField($name, $field); - } else { - $field = $this->model->addField($name); - } + $field = $this->model->addField($name, $field ?: []); + $field->never_persist = true; } elseif (is_array($field)) { // Add properties to existing field @@ -273,7 +270,7 @@ public function setFilterColumn($cols = null) // set filter to all column when null. if (!$cols) { foreach ($this->model->getFields() as $key => $field) { - if (isset($this->columns[$key]) && $this->columns[$key]) { + if (! empty($this->columns[$key])) { $cols[] = $field->short_name; } } @@ -335,17 +332,17 @@ public function getColumnDecorators($name) * Will come up with a column object based on the field object supplied. * By default will use default column. * - * @param \atk4\data\Field $f Data model field + * @param \atk4\data\Field $field Data model field * @param mixed $seed Defaults to pass to factory() when decorator is initialized * * @return TableColumn\Generic */ - public function decoratorFactory(\atk4\data\Field $f, $seed = []) + public function decoratorFactory(\atk4\data\Field $field, $seed = []) { $seed = $this->mergeSeeds( $seed, - isset($f->ui['table']) ? $f->ui['table'] : null, - isset($this->typeToDecorator[$f->type]) ? $this->typeToDecorator[$f->type] : null, + $field->ui['table'] ?? null, + $this->typeToDecorator[$field->type] ?? null, [$this->default_column ? $this->default_column : 'Generic'] ); @@ -732,12 +729,7 @@ public function getDataRowHTML() foreach ($this->columns as $name => $column) { // If multiple formatters are defined, use the first for the header cell - - if (!is_int($name)) { - $field = $this->model->getField($name); - } else { - $field = null; - } + $field = !is_int($name) ? $this->model->getField($name) : null; if (!is_array($column)) { $column = [$column];