Craft\RetourFieldType::prepValue PHP Method

prepValue() public method

Prepares the field's value for use.
public prepValue ( mixed $value ) : mixed
$value mixed
return mixed
    public function prepValue($value)
    {
        if (!$value) {
            $value = new Retour_RedirectsFieldModel();
            if ($this->model->translatable) {
                $locale = $this->element->locale;
            } else {
                $locale = craft()->language;
            }
            $value->locale = $locale;
            $result = craft()->retour->getRedirectByElementId($this->element->id, $locale);
            if ($result) {
                $value->setAttributes($result->getAttributes(), false);
            } else {
                $value->redirectSrcUrl = $this->getSettings()->defaultRedirectSrcUrl;
                $value->redirectMatchType = $this->getSettings()->defaultRedirectMatchType;
                $value->redirectHttpCode = $this->getSettings()->defaultRedirectHttpCode;
            }
        }
        $value->redirectChangeable = $this->getSettings()->redirectChangeable;
        return $value;
    }