Use page object types to select page when creating page menu item
authorMatthias Schmidt <gravatronics@live.com>
Thu, 15 May 2014 16:14:59 +0000 (18:14 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 15 May 2014 16:14:59 +0000 (18:14 +0200)
wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl
wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php
wcfsetup/install/files/lib/acp/form/PageMenuItemEditForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 2b427ee997be572043f24f2dbd33a20d59710eb6..3b0665713db22b12ed56c64b353f13a9eecf145e 100644 (file)
@@ -9,6 +9,8 @@
                var $menuItemControllerContainer = $('#menuItemControllerContainer');
                var $menuItemLinkContainer = $('#menuItemLinkContainer');
                var $menuItemParametersContainer = $('#menuItemParametersContainer');
+               var $menuItemPageContainer = $('#menuItemPageContainer');
+               var $menuItemPage = $('#menuItemPage');
                
                function handleMenuPosition() {
                        if ($menuPosition.val() === 'header') {
                
                function handleIsInternalLink() {
                        if ($isInternalLink.is(':checked')) {
+                               $menuItemPageContainer.show();
                                $menuItemControllerContainer.show();
                                $menuItemParametersContainer.show();
                                $menuItemLinkContainer.hide();
                        }
                        else {
+                               $menuItemPageContainer.hide();
                                $menuItemControllerContainer.hide();
                                $menuItemParametersContainer.hide();
                                $menuItemLinkContainer.show();
                        }
                }
                
+               function handleMenuPage() {
+                       if ($menuItemPage.val() != '0') {
+                               $menuItemControllerContainer.addClass('disabled');
+                               $menuItemControllerContainer.find('input').disable();
+                       }
+                       else {
+                               $menuItemControllerContainer.removeClass('disabled');
+                               $menuItemControllerContainer.find('input').enable();
+                       }
+               }
+               
                $menuPosition.change(handleMenuPosition);
                $('input[name=isInternalLink]').change(handleIsInternalLink);
+               $menuItemPage.change(handleMenuPage);
                
                handleMenuPosition();
                handleIsInternalLink();
+               handleMenuPage();
        });
        //]]>
 </script>
                                </dd>
                        </dl>
                        
+                       <dl id="menuItemPageContainer"{if $errorField == 'menuItemPage'} class="formError"{/if}>
+                               <dt><label for="menuItemPage">{lang}wcf.acp.pageMenu.menuItemPage{/lang}</label></dt>
+                               <dd>
+                                       <select name="menuItemPage" id="menuItemPage">
+                                               <option value="0">{lang}wcf.global.noSelection{/lang}</option>
+                                               {htmlOptions options=$pages selected=$menuItemPage}
+                                       </select>
+                                       {if $errorField == 'menuItemPage'}
+                                               <small class="innerError">
+                                                       {if $errorType == 'empty'}
+                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                       {elseif $errorType == 'noValidSelection'}
+                                                               {lang}wcf.global.form.error.noValidSelection{/lang}
+                                                       {else}
+                                                               {lang}wcf.acp.pageMenu.menuItemPage.error.{$errorType}{/lang}
+                                                       {/if}
+                                               </small>
+                                       {/if}
+                                       <small>{lang}wcf.acp.pageMenu.menuItemPage.description{/lang}</small>
+                               </dd>
+                       </dl>
+                       
                        <dl id="menuItemControllerContainer"{if $errorField == 'menuItemController'} class="formError"{/if}>
                                <dt><label for="menuItemController">{lang}wcf.acp.pageMenu.menuItemController{/lang}</label></dt>
                                <dd>
-                                       <input type="text" name="menuItemController" id="menuItemController" value="{$menuItemController}" class="long" />
+                                       <input type="text" name="menuItemController" id="menuItemController" value="{if !$pages[$menuItemPage]|isset}{$menuItemController}{/if}" class="long" />
                                        {if $errorField == 'menuItemController'}
                                                <small class="innerError">
                                                        {if $errorType == 'empty'}
index 71ffe918e1de724caf26cf89f442a29c334a7bc3..f25d35c0d29b8d28c7bfe53a03d245ac1c04a6c9 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\page\menu\item\PageMenuItemList;
 use wcf\form\AbstractForm;
 use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
+use wcf\system\page\PageManager;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
 
@@ -90,6 +91,18 @@ class PageMenuItemAddForm extends AbstractForm {
         */
        public $showOrder = 0;
        
+       /**
+        * available page object types
+        * @var array<\wcf\data\object\type\ObjectType>
+        */
+       public $pageObjectTypes = array();
+       
+       /**
+        * id of the page object type that belongs to the menu item's controller
+        * @var integer
+        */
+       public $menuItemPage = 0;
+       
        /**
         * @see \wcf\page\IPage::readParameters()
         */
@@ -100,6 +113,8 @@ class PageMenuItemAddForm extends AbstractForm {
                I18nHandler::getInstance()->register('pageMenuItem');
                
                $this->readAvailableParentMenuItems();
+               
+               $this->pageObjectTypes = PageManager::getInstance()->getObjectTypes();
        }
        
        /**
@@ -134,6 +149,7 @@ class PageMenuItemAddForm extends AbstractForm {
                if (isset($_POST['isDisabled'])) $this->isDisabled = true;
                if (isset($_POST['isInternalLink'])) $this->isInternalLink = (bool) $_POST['isInternalLink'];
                if (isset($_POST['menuItemController'])) $this->menuItemController = StringUtil::trim($_POST['menuItemController']);
+               if (isset($_POST['menuItemPage'])) $this->menuItemPage = intval($_POST['menuItemPage']);
                if (isset($_POST['menuItemParameters'])) $this->menuItemParameters = StringUtil::trim($_POST['menuItemParameters']);
                if (isset($_POST['menuPosition'])) $this->menuPosition = StringUtil::trim($_POST['menuPosition']);
                if (isset($_POST['parentMenuItem'])) $this->parentMenuItem = StringUtil::trim($_POST['parentMenuItem']);
@@ -156,8 +172,22 @@ class PageMenuItemAddForm extends AbstractForm {
                
                // validate menu item controller
                if ($this->isInternalLink) {
-                       if (empty($this->menuItemController)) {
-                               throw new UserInputException('menuItemController');
+                       if ($this->menuItemPage) {
+                               $valid = false;
+                               foreach ($this->pageObjectTypes as $page) {
+                                       if ($page->objectTypeID == $this->menuItemPage) {
+                                               $this->menuItemController = $page->className;
+                                               $valid = true;
+                                               break;
+                                       }
+                               }
+                               
+                               if (!$valid) {
+                                       throw new UserInputException('menuItemPage', 'noValidSelection');
+                               }
+                       }
+                       else if (empty($this->menuItemController)) {
+                               throw new UserInputException('menuItemPage');
                        }
                        
                        if (!class_exists($this->menuItemController)) {
@@ -273,7 +303,9 @@ class PageMenuItemAddForm extends AbstractForm {
                        'menuItemController' => $this->menuItemController,
                        'menuItemParameters' => $this->menuItemParameters,
                        'menuItemLink' => $this->menuItemLink,
+                       'menuItemPage' => $this->menuItemPage,
                        'menuPosition' => $this->menuPosition,
+                       'pages' => PageManager::getInstance()->getSelection(),
                        'pageMenuItem' => $this->pageMenuItem,
                        'parentMenuItem' => $this->parentMenuItem,
                        'showOrder' => $this->showOrder
index f191912c1b33693a91eadbc569825c44ab26415b..00b85e2f6a8dfc03d9a7570e254e35bd11ce66a7 100644 (file)
@@ -81,6 +81,12 @@ class PageMenuItemEditForm extends PageMenuItemAddForm {
                        $this->pageMenuItem = $this->menuItem->menuItem;
                        $this->parentMenuItem = $this->menuItem->parentMenuItem;
                        $this->showOrder = $this->menuItem->showOrder;
+                       
+                       foreach ($this->pageObjectTypes as $page) {
+                               if ($page->className == $this->menuItemController) {
+                                       $this->menuItemPage = $page->objectTypeID;
+                               }
+                       }
                }
        }
        
index d0ffc71cb813c65e7d1180b89ed8267dd1776a3b..42a6c41203a58410b619ba673305e51de1ff36fc 100644 (file)
@@ -1032,7 +1032,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.pageMenu.link.internal"><![CDATA[Interner Link]]></item>
                <item name="wcf.acp.pageMenu.list"><![CDATA[Menüpunkte auflisten]]></item>
                <item name="wcf.acp.pageMenu.menuItemController"><![CDATA[Controller]]></item>
-               <item name="wcf.acp.pageMenu.menuItemController.description"><![CDATA[Bitte geben Sie den vollständigen Klassennamen inklusive Namespace an, zum Beispiel „wcf\page\DashboardPage“.]]></item>
+               <item name="wcf.acp.pageMenu.menuItemController.description"><![CDATA[Sollte die gewünschte Seite in der obigen Auswahl nicht vorhanden sein, können Sie manuell den entsprechenden Controller angeben. Bitte geben Sie dabei den vollständigen Klassennamen inklusive Namespace an, zum Beispiel „wcf\page\DashboardPage“.]]></item>
                <item name="wcf.acp.pageMenu.menuItemController.error.notValid"><![CDATA[Die angegebene Klasse konnte nicht gefunden werden]]></item>
                <item name="wcf.acp.pageMenu.menuItemLink"><![CDATA[Link]]></item>
                <item name="wcf.acp.pageMenu.menuPosition"><![CDATA[Position]]></item>
@@ -1042,6 +1042,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.pageMenu.parentMenuItem"><![CDATA[Übergeordneter Menüpunkt]]></item>
                <item name="wcf.acp.pageMenu.showOrder"><![CDATA[Reihenfolge]]></item>
                <item name="wcf.acp.pageMenu.menuItemParameters"><![CDATA[Parameter]]></item>
+               <item name="wcf.acp.pageMenu.menuItemPage"><![CDATA[Seite]]></item>
+               <item name="wcf.acp.pageMenu.menuItemPage.description"><![CDATA[Wählen Sie die interne Seite aus, die Sie verlinken möchten.]]></item>
        </category>
        
        <category name="wcf.acp.pluginStore">
index 73d16ce621d7f5f9ae81bb27491aa3f1bb0a9363..51412ef988b392196e45f65a2ab6186050dc9dfd 100644 (file)
@@ -1024,7 +1024,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.pageMenu.link.internal"><![CDATA[Internal link]]></item>
                <item name="wcf.acp.pageMenu.list"><![CDATA[List Menu Items]]></item>
                <item name="wcf.acp.pageMenu.menuItemController"><![CDATA[Controller]]></item>
-               <item name="wcf.acp.pageMenu.menuItemController.description"><![CDATA[PHP class name including namespace, e.g. “wcf\page\DashboardPage”.]]></item>
+               <item name="wcf.acp.pageMenu.menuItemController.description"><![CDATA[If a page is not available in the selection above, you can enter the related controller manually. Enter the PHP class name including namespace, e.g. “wcf\page\DashboardPage”.]]></item>
                <item name="wcf.acp.pageMenu.menuItemController.error.notValid"><![CDATA[Unable to find the provided class name]]></item>
                <item name="wcf.acp.pageMenu.menuItemLink"><![CDATA[Link]]></item>
                <item name="wcf.acp.pageMenu.menuPosition"><![CDATA[Position]]></item>
@@ -1034,6 +1034,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.pageMenu.parentMenuItem"><![CDATA[Parent Menu Item]]></item>
                <item name="wcf.acp.pageMenu.showOrder"><![CDATA[Display Order]]></item>
                <item name="wcf.acp.pageMenu.menuItemParameters"><![CDATA[Parameters]]></item>
+               <item name="wcf.acp.pageMenu.menuItemPage"><![CDATA[Page]]></item>
+               <item name="wcf.acp.pageMenu.menuItemPage.description"><![CDATA[Choose the internal page you want to link.]]></item>
        </category>
        
        <category name="wcf.acp.rebuildData">