Jump to content


Photo

Creating new admin page


  • Please log in to reply
1 reply to this topic

#1 adamkiss

adamkiss

    Master of the universe

  • Moderators
  • 1,088 posts
  • 293

Posted 26 June 2011 - 08:23 AM

Hi Ryan,

I need to create new page in admin section. I'd like to add it in menu between PAGES and MODULES (or whatever the next item is).

I also like to load pages with hardcoded query, and list them in this order:
  $page->title   |   $parent->title   |   $page->intFieldValue   |   $page->edit()->url

I believe, that query and table aren't problem. The problem is where to create the file itself and how to add it into the admin menu. Also, I would like to hook this file to permissions system (PW2.0)

Thanks!

#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3386

  • LocationAtlanta, GA

Posted 26 June 2011 - 11:32 AM

To add a new menu item in the admin, you just go in there and add a page like you would anywhere else (and use the 'admin' template for that page, or one of your own if you prefer). If you want it to live between 'Pages' and 'Modules' then just drag it between those two.

If this is something that you want to do automatically (like as part of a module installer) let me know and I'll post a code example.

My understanding is that you want to display a custom HTML table of pages on your new admin page. You can go about this in two ways:

Option 1
You can do it the same way as you would for any other template in your site. Only you would select your new template for that page rather than the 'admin' template. You would set access with the page (2.0) or with the template (2.1). The advantage of this approach is that it's really easy. The disadvantage is that your page may not look like the rest of the admin or use it's systems (which may or may not be useful to your need).

Option 2
Use the 'admin' template for your page, create a new 'Process' module and install it. When you edit your new page, it will ask you what Process it should run, and you'll select the new Process module you created. This is the approach you want to take if you want to maintain a consistent admin experience or you want to package your functionality into a reusable module.

Here's an example of how to create a Process module:

/site/modules/ProcessHello.module
<?php
class ProcessHello extends Process {

    public static function getModuleInfo() {
        return array(
            'title' => 'Hello',
            'summary' => 'Simple Process module demo',
            'version' => 001,
            );
    }

    public function execute() {
        return "<p><a href='./hi'>hi</a> or <a href='./bye'>bye</a></p>";
    }

    public function executeHi() {
        $this->message("Well hello"); 
        return "<p>You clicked hi!</p>";
    }

    public function executeBye() {
        $this->setFuel('processHeadline', 'Goodbye?'); 
        $this->error('Not so fast!'); 
        return "<p>You clicked bye!</p>";
    }
}

Regarding your question about permissions: The user must have access to the page your Process is on before they can execute it. And they will already by default (unless you change around the page/template permissions). But in PW 2.0, they must also have access to a permission with the same name as the module. PW 2.0 installs that automatically with your module. This is only applicable to non-superuser roles (superuser can already access everything regardless of permission).

In 2.1, PW doesn't install a permission and access to the Process is assumed if user has access to the page it's on.  If you want PW 2.1 to behave like PW 2.0 and require a specific permission before it'll run the module, you want to specify it in your getModuleInfo function:

<?php

    public static function getModuleInfo() {
        return array(
            'title' => 'Hello',
            'summary' => 'Simple Process module demo',
            'version' => 001,
            'permission' => 'name-of-permission', // NOTE THIS 
            );
    }

Replace 'name-of-permission' with the permission name you want it to require. It can be any existing permission, or one that you've created.

Your module can also check other permissions on-the-fly, but I won't get into that here unless someone wants me to.








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users