Skip to content

Commit

Permalink
Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Sep 17, 2024
1 parent 94c5812 commit 6208144
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function formatBoolean(string $field, mixed $value, array $options): stri
public function formatDateTime(string $field, mixed $value, array $options): string
{
if ($value === null) {
return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
return $this->nullValueDisplay();
}

if ($value instanceof Date) {
Expand All @@ -244,7 +244,7 @@ public function formatDateTime(string $field, mixed $value, array $options): str
}

return (string)$this->Time->i18nFormat($value, $options['format'] ?? $this->getConfig('dateTimeFormat'), '')
?: $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
?: $this->nullValueDisplay();
}

/**
Expand All @@ -257,7 +257,7 @@ public function formatDateTime(string $field, mixed $value, array $options): str
public function formatEnum(string $field, UnitEnum|BackedEnum|string|int|null $value, array $options): string
{
if ($value === null) {
return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
return $this->nullValueDisplay();
}

if (is_scalar($value)) {
Expand Down Expand Up @@ -292,6 +292,16 @@ public function formatDisplayField(string $value, array $options): string
return $this->createViewLink($value, ['escape' => false]);
}

/**
* Display for `null` values
*
* @return string
*/
protected function nullValueDisplay(): string
{
return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
}

/**
* Returns a formatted relation output for a given field
*
Expand Down

0 comments on commit 6208144

Please sign in to comment.