Skip to content

Commit

Permalink
Improve empty check
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Dec 18, 2024
1 parent ffe1601 commit 00b3b0c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/EventListener/DataContainer/LeadLabelListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,17 @@ public function __invoke(array $row, string $label): string
$records = $this->connection->fetchAllAssociative('SELECT name, value, label FROM tl_lead_data WHERE pid=?', [$row['id']]);

foreach ($records as $record) {
$label = StringUtil::deserialize($record['label']);
$value = (!\is_array($label) && !empty($label)) || (\is_array($label) && array_filter($label)) ? $label : StringUtil::deserialize($record['value']);
// Try to use label over value if it is a non-empty scalar value or a non-empty array
foreach ([$record['label'], $record['value']] as $value) {
$value = StringUtil::deserialize($value);

if (
(!\is_array($value) && '' !== (string) $value)
|| (\is_array($value) && [] !== array_filter($value))
) {
break;
}
}

if ($this->stringParser) {
$this->stringParser->flatten($value, $record['name'], $tokens);
Expand Down

0 comments on commit 00b3b0c

Please sign in to comment.