/** * @see \cms\acp\form\PageAddForm::validateAlias() */ protected function validateAlias() { if (empty($this->alias)) { throw new UserInputException('alias'); } if (!PageUtil::isValidAlias($this->alias)) { throw new UserInputException('alias', 'notValid'); } if (!PageUtil::isAvailableAlias($this->alias, $this->parentID ?: null, $this->pageID)) { throw new UserInputException('alias', 'notUnique'); } }
/** * Copies a specific page. */ public function copy() { $object = $this->getSingleObject(); $data = $object->getDecoratedObject()->getData(); // remove unique or irrelevant properties unset($data['pageID']); unset($data['isHome']); unset($data['clicks']); // ensure unique aliases $i = 1; $alias = $data['alias'] . '-copy'; do { $data['alias'] = $alias . $i; $i++; } while (!PageUtil::isAvailableAlias($data['alias'], $object->parentID)); // perform creation of copy $this->parameters['data'] = $data; $page = $this->create(); $pageID = $page->pageID; // copy contents $contents = $object->getContents(); $tmp = array(); foreach (array('body', 'sidebar') as $position) { foreach ($contents[$position] as $content) { //recreate $data = $content->getDecoratedObject()->getData(); $oldID = $data['contentID']; unset($data['contentID']); $data['pageID'] = $pageID; $action = new ContentAction(array(), 'create', array('data' => $data)); $return = $action->executeAction(); $tmp[$oldID] = $return['returnValues']->contentID; } } // setting new IDs $contents = new ContentList(); $contents->getConditionBuilder()->add('pageID = ?', array($pageID)); $contents->readObjects(); $contents = $contents->getObjects(); foreach ($contents as $content) { $update = array(); if (isset($tmp[$content->parentID])) { $editor = new ContentEditor($content); $update['parentID'] = $tmp[$content->parentID]; $editor->update($update); } } }
/** * Validates the alias. */ protected function validateAlias() { // build alias automatically if (empty($this->alias)) { $titles = I18nHandler::getInstance()->getValues('title'); // prefer english aliases, otherwise use default language $language = LanguageFactory::getInstance()->getLanguageByCode('en'); if ($language === null) { $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID()); } $this->alias = PageUtil::buildAlias($titles[$language->languageID]); } if (!PageUtil::isValidAlias($this->alias)) { throw new UserInputException('alias', 'notValid'); } if (!PageUtil::isAvailableAlias($this->alias, $this->parentID ?: null)) { throw new UserInputException('alias', 'notUnique'); } }