Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting value to null when empty = remove from table #7

Merged
merged 1 commit into from
Mar 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions plugins/system/fields/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,29 @@ public function onContentAfterSave($context, $item, $isNew, $data = array())
// Loop over the fields
foreach ($fields as $field)
{
// Determine the value if it is available from the data
$value = key_exists($field->name, $data['com_fields']) ? $data['com_fields'][$field->name] : $field->rawvalue;
// Determine the value if it is (un)available from the data
if (key_exists($field->name, $data['com_fields']))
{
if ($data['com_fields'][$field->name] === false)
{
$value = null;
}
else
{
$value = $data['com_fields'][$field->name];
}
}
// Field not available on form, use stored value
else
{
$value = $field->rawvalue;
}

// If no value set (empty) remove value fom database
if (empty($value))
{
$value = null;
}

// JSON encode value for complex fields
if (is_array($value) && (count($value, COUNT_NORMAL) !== count($value, COUNT_RECURSIVE) || !count(array_filter(array_keys($value), 'is_numeric'))))
Expand Down