Skip to content

Instantly share code, notes, and snippets.

@tshafer
Created February 10, 2017 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshafer/d8609ee81cd50908badbfbcb8a61fce2 to your computer and use it in GitHub Desktop.
Save tshafer/d8609ee81cd50908badbfbcb8a61fce2 to your computer and use it in GitHub Desktop.
$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