示例#1
0
 private function saveLink(Website $website)
 {
     $text = $website->getText();
     $valid = true;
     if (!Validate::url($this->linkUrl)) {
         $text->addError($text->t("links.url") . " " . Validate::getLastError($text));
         $valid = false;
     }
     if (!Validate::stringLength($this->linkName, 1, LinkRepository::MAX_LINK_TEXT_LENGTH)) {
         $text->addError($text->t("links.text") . " " . Validate::getLastError($text));
         $valid = false;
     }
     if (!$valid) {
         return;
     }
     $link = Link::createSaveable(0, $this->menu->getId(), new Uri($this->linkUrl), $this->linkName);
     $linkRepo = new LinkRepository($website->getDatabase());
     $linkRepo->saveLink($link);
     $text->addMessage($text->t("main.link") . " " . $text->t("editor.is_created"), Link::of($text->getUrlPage("add_link", $this->menu->getId()), $text->t("links.create_another")));
     $this->addedLink = true;
 }