Skip to content

Commit

Permalink
Update Direct.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 authored Oct 9, 2024
1 parent 3edd4cd commit 28ea670
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Mapping/DataTarget/Direct.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,21 @@ protected function checkAssignData($newData, $valueContainer, $getter)
if (count($fieldNameParts) === 3) {
$fieldName = $fieldNameParts[2];
}

$fieldDefinition = $this->getFieldDefinition($valueContainer, $fieldName);
if ($this->writeIfTargetIsNotEmpty === false && !$fieldDefinition->isEmpty($currentData)) {

try{
$fieldDefinition = $this->getFieldDefinition($valueContainer, $fieldName);
$currentDataIsEmpty= $fieldDefinition->isEmpty($currentData);
$newDataIsEmpty = $fieldDefinition->isEmpty($newData);
} catch (InvalidConfigurationException $e) {
$currentDataIsEmpty= empty($currentData);
$newDataIsEmpty = empty($newData);
}

if ($this->writeIfTargetIsNotEmpty === false && !$currentDataIsEmpty) {
return false;
}

if ($this->writeIfSourceIsEmpty === false && $fieldDefinition->isEmpty($newData)) {
if ($this->writeIfSourceIsEmpty === false && $newDataIsEmpty) {
return false;
}

Expand Down

0 comments on commit 28ea670

Please sign in to comment.