Skip to content

Commit

Permalink
refactor to use shorthand syntax (atk4#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov authored Feb 18, 2020
1 parent f4d5a13 commit 2edfaf5
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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']
);

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 2edfaf5

Please sign in to comment.