setEntry($entry); } if ($url) { $this->setUrl($url); } } /** * Get the Entry * * @api * @return Entry */ public function getEntry() { return $this->entry; } /** * Set the Entry * * @api * @param Entry $entry Entry Control * @return static */ public function setEntry(Entry $entry) { $entry->setScriptEvents(true) ->checkId(); $this->entry = $entry; return $this; } /** * Get the submit url * * @api * @return string */ public function getUrl() { return $this->url; } /** * Set the submit url * * @api * @param string $url Submit url * @return static */ public function setUrl($url) { $this->url = (string)$url; return $this; } /** * @see ScriptFeature::prepare() */ public function prepare(Script $script) { $script->setScriptInclude(ScriptInclude::TEXTLIB); $controlScript = new ControlScript($this->entry, $this->getScriptText(), ScriptLabel::ENTRYSUBMIT); $controlScript->prepare($script); return $this; } /** * Get the script text * * @return string */ protected function getScriptText() { $url = $this->buildCompatibleUrl(); $entryName = $this->entry->getName(); $link = Builder::escapeText($entryName . $url . "="); return " declare Value = TextLib::URLEncode(Entry.Value); OpenLink({$link}^Value, CMlScript::LinkType::Goto); "; } /** * Build the submit url compatible for the Entry parameter * * @return string */ protected function buildCompatibleUrl() { $url = $this->url; $paramsBegin = stripos($url, '?'); if (!is_int($paramsBegin) || $paramsBegin < 0) { $url .= '?'; } else { $url .= '&'; } return $url; } }