简体   繁体   中英

How to change the selected entry in TYPO3 pagetree

I am making a backend extension that, changes which page it is working on upon clicking a link in the work area to the right of the pagetree. The problem is: the pagetree doesn't update according to the ID that is presented in the work area.

The ID is changed by passing query parameter ID to the mod.php-module, and works as expected. I have tried updating the page tree via

   t3lib_BEfunc::openPageTree($this->id);
   t3lib_BEfunc::setUpdateSignal('updatePageTree');

and later

   <script type="text/javascript">'.t3lib_BEfunc::getUpdateSignalCode().'</script>

to be included in the output. This also works (the pagetree is refreshed, and hidden subpages of the passed ID is revealed), except the greyness indicating the current page in the page tree is left at its previous position.

Any idea as to how to make the pagetree reflect the new $this->id ?

Here's how I did it. In the PHP code of my BE module, I only called openPageTree like so:

t3lib_BEfunc::openPageTree(76,false);

I did not call setUpdateSignal because the whole "update signal" process felt a bit weird to me. Please also note that openPageTree now has a second parameter, which is required.

To my understanding, this call should be sufficient to set the state of tree in the user session server-side. Now comes the client side.

In the JavaScript code of my extension, I simply select the appropriate page ID and that's it:

<script type="text/javascript">
  if (top && top.TYPO3.Backend.NavigationContainer.PageTree) {
    top.TYPO3.Backend.NavigationContainer.PageTree.select(76);
  }
</script>

While looking through the source of the page tree, I realized that it will always select top.fsMod.recentIds['web'] after a refresh. Sadly, I wasn't able to determine how to properly inject a value there. It seemed to me like the value is only supposed to be adjusted through user interaction (meaning, the user clicked on a node in the page tree).

In TYPO3 6.1, you have a Javascript function to jump to a web module:

/**
 * jump the backend to a module
 */
function jump(url, modName, mainModName, pageId) {
    if (isNaN(pageId)) {
        pageId = -2;
    }
    // clear information about which entry in nav. tree that might have been highlighted.
    top.fsMod.navFrameHighlightedID = [];
    top.fsMod.recentIds['web'] = pageId;

    if (top.TYPO3.Backend.NavigationContainer.PageTree) {
        top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
    }

    top.nextLoadModuleUrl = url;
    top.TYPO3.ModuleMenu.App.showModule(modName);
}

You can use it like this:

<a onclick="jump('alt_doc.php?&edit[pages][\'uid_page\']=edit','web_list', 'web', 'uid_page')" href="#"><span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-open">&nbsp;</span></a>

Just replace "uid_page" by your correct uid:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM