Jump to content

Recommended Posts

Posted

Currently the page tree(name=page) under admin is locked. I would like to generate a page to place above the page tree, using $page->sort = 0, but it is not possible before removing the statusSystemOverride attached to it. I tried to remove the status like this:

$pages = $this->wire('pages');
$tree = $pages->get('name=page, template=admin');
$tree->removeStatus(Page::statusSystemOverride);
$tree->save();

And recover the status after saving my generated page

$p = new Page();
$p->template = 'admin';
$p->title = 'Some Page';
$p->name = 'somepage';
$p->parent = $pages->get(2);
$p->process = 'SomeProcess';
$p->sort = 0;
$p->save();

$tree->addStatus(Page::statusSystemOverride);
$tree->save();

And the Page group is disappeared on the sidebar. I cannot recover it and need to reinstall the PW. I am developing a module so I would like to know the correct way to place page above the page tree by API not by drag and drop. Thanks.

Posted

 

Do you want something like this? Moving a page before Admin > Pages?

image.png.87e3ee2d0b14811145b10482d554d7fb.png

Then try using $pages->insertBefore(), no need to change page status at all. 

$anchor = $pages(3); // `Pages` page
$sortee = $pages(1354); // page to move before `Pages`
$pages->insertBefore($sortee, $anchor);

 

<?php
/**
 * Sort one page before another (for pages using manual sort)
 *
 * Note that if given $sibling parent is different from `$page` parent, then the `$pages->save()`
 * method will also be called to perform that movement.
 *
 * @param Page $page Page to move/sort
 * @param Page $sibling Sibling that page will be moved/sorted before
 * @param bool $after Specify true to make $page move after $sibling instead of before (default=false)
 * @throws WireException When conditions don't allow page insertions
 *
 */
public function insertBefore(Page $page, Page $sibling, $after = false) { /* ... */ }

EDIT: Moving before Tree works too

$anchor = $pages(8); // `Tree` page
$sortee = $pages(1354); // page to move before `Tree`
$pages->insertBefore($sortee, $anchor);

 

  • Like 4

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...