diff --git a/app/Utils/Helpers.php b/app/Utils/Helpers.php index b9947fedc9b2..f2fa72b30fe7 100644 --- a/app/Utils/Helpers.php +++ b/app/Utils/Helpers.php @@ -40,16 +40,16 @@ class Helpers } /** - * A centralised way to format the custom fields content. + * A centralised method to format the custom fields content. * - * @param mixed $custom_fields + * @param mixed|null $custom_fields * @param mixed $field * @param mixed $value * @param \App\Models\Client|null $client * * @return null|string */ - public function formatCustomFieldValue($custom_fields, $field, $value, Client $client = null): ?string + public function formatCustomFieldValue($custom_fields = null, $field, $value, Client $client = null): ?string { $custom_field = ''; @@ -76,4 +76,24 @@ class Helpers break; } } + + /** + * A centralised method to make custom field. + * @param mixed|null $custom_fields + * @param mixed $field + * + * @return string + */ + public function makeCustomField($custom_fields = null, $field): string + { + if ($custom_fields && property_exists($custom_fields, $field)) { + $custom_field = $custom_fields->{$field}; + + $custom_field_parts = explode('|', $custom_field); + + return $custom_field_parts[0]; + } + + return ''; + } }