Skip to content

Commit

Permalink
Account for null values for formatEnum()
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad authored May 2, 2024
1 parent c003ceb commit e57e739
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,15 @@ public function formatTime(string $field, mixed $value, array $options): string
* Format an enum for display
*
* @param string $field Name of field.
* @param \UnitEnum|\BackedEnum|string|int $value Value of field.
* @param \UnitEnum|\BackedEnum|string|int|null $value Value of field.
* @return string
*/
public function formatEnum(string $field, UnitEnum|BackedEnum|string|int $value, array $options): string
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']);
}

if (is_scalar($value)) {
return (string)$value;
}
Expand Down

0 comments on commit e57e739

Please sign in to comment.