Modify a field value before the element is saved I have a simple plugin with a field that extends the Craft PlainText field.

Is there some kind of function I can use to modify the field's submitted value before the element is saved?

class myField extends craft\fields\PlainText
{
    private function modifyPostedValue()
    {
        if ($PostedValue == “foo”)  {
            $PostedValue = “bar”;
            // save “bar” to database
        } else {
            // save “foo” to database
        };
    }
}
It turns out that serializeValue is what I needed.

public function serializeValue($value, ElementInterface $element = null)
{   
    if ($value == 'foo') {
        $value = 'bar';
    }

    return $value;
}