public function prepValueFromPost($value) { $result = null; if (empty($value)) { $result = $this->prepValue($value); } else { $result = new Retour_RedirectsFieldModel($value); } $urlParts = parse_url($this->element->url); $url = $urlParts['path'] ? $urlParts['path'] : $this->element->url; $result->redirectDestUrl = $url; $result->associatedElementId = $this->element->id; if ($this->model->translatable) { $locale = $this->element->locale; } else { $locale = craft()->language; } $result->locale = $locale; if ($result->redirectMatchType == "exactmatch" && $result->redirectSrcUrl !== '') { $result->redirectSrcUrl = '/' . ltrim($result->redirectSrcUrl, '/'); } /* -- Restore the default fields we don't let the user edit */ $oldRecord = craft()->retour->getRedirectByElementId($this->element->id, $locale); if ($oldRecord) { $result->hitCount = $oldRecord->hitCount; $result->hitLastTime = $oldRecord->hitLastTime; } try { $result->redirectSrcUrlParsed = craft()->templates->renderObjectTemplate($result->redirectSrcUrl, $this->element); } catch (Exception $e) { RetourPlugin::log("Template error in the `redirectSrcUrl` field.", LogLevel::Info, true); } return $result; }