From 491d080ab4df682b46b7f2d35a4dd304c502816c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 25 Dec 2020 12:27:37 +0100 Subject: [PATCH] add new makeCustomField (centralised refactor) --- app/Utils/Helpers.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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 ''; + } }