Skip to content

Instantly share code, notes, and snippets.

@yuklia
Created June 1, 2016 13:44
Show Gist options
  • Save yuklia/4662bf1212adaa6c81da94819d147d54 to your computer and use it in GitHub Desktop.
Save yuklia/4662bf1212adaa6c81da94819d147d54 to your computer and use it in GitHub Desktop.
protected function _serializeField(DataObject $object, $field, $defaultValue = null, $unsetEmpty = false)
{
$value = $object->getData($field);
if (empty($value) && $unsetEmpty) {
$object->unsetData($field);
} else {
if (is_string($value)) {
$object->setData($field, $value ?: $defaultValue);
} else {
$object->setData($field, serialize($value ?: $defaultValue));
}
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment