Created
February 10, 2017 17:24
-
-
Save tshafer/d8609ee81cd50908badbfbcb8a61fce2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$customFields = json_decode($value, true); | |
if ( ! empty($customFields)) { | |
$attributes = []; | |
foreach ($customFields as $custom_field) { | |
$customFieldData = explode('::::', $custom_field); | |
$attributes[head($customFieldData)] = end($customFieldData); | |
} | |
return $this->attributes['custom_fields'] = json_encode($attributes); | |
} | |
if ( ! str_contains($value, '::::')) { | |
return $this->attributes['custom_fields'] = $value; | |
} | |
// Remove required | |
$value = explode(',', $value); | |
if (is_array($value)) { | |
$data = []; | |
$value = array_map(function ($value) { | |
return trim(str_replace('::::required', '', preg_replace(['/^\[/', '/\]$/'], '', $value)), '"'); | |
}, $value); | |
foreach ($value as $v) { | |
$initData = explode('::::', $v); | |
if(count($initData) == 2) { | |
if ($initData[1] != "null") { | |
$data[$initData[0]] = $initData[1]; | |
} | |
} | |
} | |
return $this->attributes['custom_fields'] = json_encode($data); | |
} else { | |
return $this->attributes['custom_fields'] = $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment