</dd>
</dl>
+ {if $action == 'add'}
+ <dl>
+ <dt></dt>
+ <dd>
+ <label><input type="checkbox" id="addPageToMainMenu" name="addPageToMainMenu" value="1"{if $addPageToMainMenu} checked{/if}> {lang}wcf.acp.page.addPageToMainMenu{/lang}</label>
+
+ <script data-relocate="true">
+ elById('addPageToMainMenu').addEventListener('change', function() {
+ if (this.checked) {
+ elShow(elById('parentMenuItemDl'));
+ }
+ else {
+ elHide(elById('parentMenuItemDl'));
+ }
+ });
+ </script>
+ </dd>
+ </dl>
+
+ <dl id="parentMenuItemDl"{if $errorField == 'parentMenuItemID'} class="formError"{/if}{if !$addPageToMainMenu} style="display: none"{/if}>
+ <dt><label for="parentMenuItemID">{lang}wcf.acp.menu.item.parentItem{/lang}</label></dt>
+ <dd>
+ <select name="parentMenuItemID" id="parentMenuItemID">
+ <option value="0">{lang}wcf.global.noSelection{/lang}</option>
+
+ {foreach from=$menuItemNodeList item=menuItemNode}
+ <option value="{@$menuItemNode->itemID}"{if $menuItemNode->itemID == $parentMenuItemID} selected{/if}>{if $menuItemNode->getDepth() > 1}{@" "|str_repeat:($menuItemNode->getDepth() - 1)}{/if}{lang}{$menuItemNode->title}{/lang}</option>
+ {/foreach}
+ </select>
+ {if $errorField == 'parentMenuItemID'}
+ <small class="innerError">
+ {if $errorType == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {else}
+ {lang}wcf.acp.page.parentMenuItem.error.{@$errorType}{/lang}
+ {/if}
+ </small>
+ {/if}
+ </dd>
+ </dl>
+ {/if}
+
{event name='dataFields'}
</div>
</div>
{foreach from=$availableLanguages item=availableLanguage}
<div id="language{@$availableLanguage->languageID}" class="tabMenuContent">
<div class="section">
- <dl{if $errorField == 'title'} class="formError"{/if}>
+ {assign var='__errorFieldName' value='title_'|concat:$availableLanguage->languageID}
+ <dl{if $errorField == $__errorFieldName} class="formError"{/if}>
<dt><label for="title{@$availableLanguage->languageID}">{lang}wcf.global.title{/lang}</label></dt>
<dd>
<input type="text" id="title{@$availableLanguage->languageID}" name="title[{@$availableLanguage->languageID}]" value="{if !$title[$availableLanguage->languageID]|empty}{$title[$availableLanguage->languageID]}{/if}" class="long" maxlength="255">
- {if $errorField == 'title'}
+ {if $errorField == $__errorFieldName}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
</dl>
{if $pageType != 'system'}
- <dl{if $errorField == 'content'} class="formError"{/if}>
+ {assign var='__errorFieldName' value='content_'|concat:$availableLanguage->languageID}
+ <dl{if $errorField == $__errorFieldName} class="formError"{/if}>
<dt><label for="content{@$availableLanguage->languageID}">{lang}wcf.acp.page.content{/lang}</label></dt>
<dd>
{include file='__pageAddContent' languageID=$availableLanguage->languageID}
- {if $errorField == 'content'}
+ {if $errorField == $__errorFieldName}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
</dd>
</dl>
- <dl{if $errorField == 'metaDescription'} class="formError"{/if}>
+ {assign var='__errorFieldName' value='metaDescription_'|concat:$availableLanguage->languageID}
+ <dl{if $errorField == $__errorFieldName} class="formError"{/if}>
<dt><label for="metaDescription{@$availableLanguage->languageID}">{lang}wcf.acp.page.metaDescription{/lang}</label></dt>
<dd>
<input type="text" class="long" name="metaDescription[{@$availableLanguage->languageID}]" id="metaDescription{@$availableLanguage->languageID}" value="{if !$metaDescription[$availableLanguage->languageID]|empty}{$metaDescription[$availableLanguage->languageID]}{/if}">
- {if $errorField == 'metaDescription'}
+ {if $errorField == $__errorFieldName}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
</dd>
</dl>
- <dl{if $errorField == 'metaKeywords'} class="formError"{/if}>
+ {assign var='__errorFieldName' value='metaKeywords_'|concat:$availableLanguage->languageID}
+ <dl{if $errorField == $__errorFieldName} class="formError"{/if}>
<dt><label for="metaKeywords{@$availableLanguage->languageID}">{lang}wcf.acp.page.metaKeywords{/lang}</label></dt>
<dd>
<input type="text" class="long" name="metaKeywords[{@$availableLanguage->languageID}]" id="metaKeywords{@$availableLanguage->languageID}" value="{if !$metaKeywords[$availableLanguage->languageID]|empty}{$metaKeywords[$availableLanguage->languageID]}{/if}">
- {if $errorField == 'metaKeywords'}
+ {if $errorField == $__errorFieldName}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
use wcf\data\box\Box;
use wcf\data\box\BoxList;
use wcf\data\language\Language;
+use wcf\data\menu\item\MenuItem;
+use wcf\data\menu\item\MenuItemAction;
+use wcf\data\menu\item\MenuItemEditor;
+use wcf\data\menu\item\MenuItemNodeTree;
+use wcf\data\menu\MenuCache;
use wcf\data\page\Page;
use wcf\data\page\PageAction;
use wcf\data\page\PageEditor;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\UserInputException;
use wcf\system\html\input\HtmlInputProcessor;
+use wcf\system\language\I18nHandler;
use wcf\system\language\LanguageFactory;
use wcf\system\request\LinkHandler;
use wcf\system\request\RouteHandler;
*/
public $allowSpidersToIndex = 1;
+ /**
+ * true if page should be added to the main menu
+ * @var boolean
+ */
+ public $addPageToMainMenu = 0;
+
+ /**
+ * parent menu item id
+ * @var integer
+ */
+ public $parentMenuItemID = null;
+
+ /**
+ * menu item node tree
+ * @var MenuItemNodeTree
+ */
+ public $menuItems = null;
+
/**
* @inheritDoc
*/
if (isset($_POST['isLandingPage'])) $this->isLandingPage = 1;
if (isset($_POST['availableDuringOfflineMode'])) $this->availableDuringOfflineMode = 1;
if (isset($_POST['allowSpidersToIndex'])) $this->allowSpidersToIndex = 1;
+ if (isset($_POST['addPageToMainMenu'])) $this->addPageToMainMenu = 1;
if (isset($_POST['applicationPackageID'])) $this->applicationPackageID = intval($_POST['applicationPackageID']);
+ if (!empty($_POST['parentMenuItemID'])) $this->parentMenuItemID = intval($_POST['parentMenuItemID']);
if (isset($_POST['customURL']) && is_array($_POST['customURL'])) $this->customURL = array_map('mb_strtolower', ArrayUtil::trim($_POST['customURL']));
if (isset($_POST['title']) && is_array($_POST['title'])) $this->title = ArrayUtil::trim($_POST['title']);
$this->validateApplicationPackageID();
+ $this->validateParentMenuItemID();
+
$this->validateCustomUrls();
+ $this->validateTitle();
+
$this->validateBoxIDs();
if ($this->pageType == 'text') {
}
}
+ /**
+ * Validates page title.
+ *
+ * @throws UserInputException
+ */
+ protected function validateTitle() {
+ if ($this->addPageToMainMenu) {
+ if ($this->isMultilingual) {
+ foreach ($this->availableLanguages as $language) {
+ if (empty($this->title[$language->languageID])) {
+ throw new UserInputException('title_' . $language->languageID);
+ }
+ }
+ }
+ else {
+ if (empty($this->title[0])) {
+ throw new UserInputException('title');
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates parent menu item id.
+ *
+ * @throws UserInputException
+ */
+ protected function validateParentMenuItemID() {
+ if ($this->addPageToMainMenu && $this->parentMenuItemID) {
+ $parentMenuItem = new MenuItem($this->parentMenuItemID);
+ if (!$parentMenuItem->itemID || $parentMenuItem->menuID != MenuCache::getInstance()->getMainMenuID()) {
+ throw new UserInputException('parentMenuItemID', 'invalid');
+ }
+ }
+ }
+
/**
* Validates box ids.
*
// save acl
SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.page', $page->pageID, $this->aclValues);
+ // add page to main menu
+ if ($this->addPageToMainMenu) {
+ $menuItemAction = new MenuItemAction([], 'create', ['data' => [
+ 'isDisabled' => $this->isDisabled ? 1 : 0,
+ 'title' => (!$this->isMultilingual ? $this->title[0] : ''),
+ 'pageID' => $page->pageID,
+ 'menuID' => MenuCache::getInstance()->getMainMenuID(),
+ 'parentItemID' => $this->parentMenuItemID,
+ 'identifier' => StringUtil::getRandomID(),
+ 'packageID' => 1
+ ]]);
+ $menuItemAction->executeAction();
+
+ if ($this->isMultilingual) {
+ $returnValues = $menuItemAction->getReturnValues();
+ $menuItem = $returnValues['returnValues'];
+
+ $data = ['identifier' => 'com.woltlab.wcf.generic' . $menuItem->itemID];
+ $data['title'] = 'wcf.menu.item.' . $data['identifier'];
+ I18nHandler::getInstance()->setValues('title', $this->title);
+ I18nHandler::getInstance()->save('title', $data['title'], 'wcf.menu');
+
+ $menuItemEditor = new MenuItemEditor($menuItem);
+ $menuItemEditor->update($data);
+ }
+ }
+
// call saved event
$this->saved();
if ($box->visibleEverywhere) $this->boxIDs[] = $box->boxID;
}
}
+
+ $this->menuItems = new MenuItemNodeTree(MenuCache::getInstance()->getMainMenuID(), null, false);
}
/**
'availableLanguages' => $this->availableLanguages,
'availableBoxes' => $this->availableBoxes,
'pageNodeList' => (new PageNodeTree())->getNodeList(),
- 'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues)
+ 'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues),
+ 'addPageToMainMenu' => $this->addPageToMainMenu,
+ 'parentMenuItemID' => $this->parentMenuItemID,
+ 'menuItemNodeList' => $this->menuItems->getNodeList()
]);
}
}