Skip to content

Commit

Permalink
Remove unnecessary getDefaultValues method
Browse files Browse the repository at this point in the history
Defaults can be set via processValues instead.
  • Loading branch information
theodorejb committed Nov 29, 2024
1 parent 5d6389d commit fa4340c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
11 changes: 0 additions & 11 deletions src/Entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ protected function getSelectProps(): array
return [];
}

/**
* Allows default values to be specified for mapped properties.
* These defaults are only used when adding entities.
*/
protected function getDefaultValues(): array
{
return [];
}

/**
* Can modify the filter or throw an exception if it is invalid
* @param mixed[] $filter
Expand Down Expand Up @@ -207,13 +198,11 @@ public function addEntities(array $entities): array
return [];
}

$defaultValues = $this->getDefaultValues();
$rows = [];
$existingIds = [];

foreach ($entities as $key => $entity) {
unset($entity[$this->idField]); // any ID posted to API should be ignored
$entity = array_replace_recursive($defaultValues, $entity);
$entity = $this->processValues($entity, []);

// if processValues sets an ID for an existing item, don't insert a new row for it
Expand Down
10 changes: 6 additions & 4 deletions test/src/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ protected function getSelectProps(): array
];
}

protected function getDefaultValues(): array
protected function processValues(array $data, array $ids): array
{
return [
'isDisabled' => false,
];
if (!$ids && !isset($data['isDisabled'])) {
$data['isDisabled'] = false;
}

return $data;
}
}

0 comments on commit fa4340c

Please sign in to comment.