I was watching Joe Brinkman's demo on developing MVC modules some time ago, and something caught my attention. The way he was creating an admin entry in the Persona Bar was simple and efficient. I made a mental note of it at the time and today I was confronted with the same situation again. We had to manually create an admin page in Persona Bar. Apparently, you can't do that easily in DNN 9. In the page settings screen, the Admin page can't be chosen as the parent page. It's disabled.
To manually create a page in Persona Bar
There is a workaround that Radu Niculcea from DNN Sharp found. I will give it to you here, though the purpose of this article is to show you how to do it programmatically.
1. Change the permissions of the Admin page so it's viewable to Registered Users
2. Create the custom administration page and select the Admin page as the parent, which now is selectable
3. Remove the Registered User view permission for the Admin page
There is another workaround that was suggested by Josh Slaughter. That is, use the Add Multiple Pages feature from Persona Bar which does let you select Admin as the parent page.
Creating Persona Bar entries programmatically
Anyway, going back to creating the Persona Bar entry for a module, let me first give you an overview of how we used to do it before discovering this gem. We would use the IUpradebale interface that gets called when a module extension is installed/updated. In this interface, we would call DNN methods to create the page under admin. The solution is pretty much described in this article, except the code that creates the pages.
The problem with this solution is that as new portals are created, they didn't contain our admin page. So, in the end, we've implement an initialization method that gets called before other code to check that the admin page exists. We have quite some code for this and let me tell you, there's all sort of issues to take into account like what happens if the page is in recycle bin.
The awesome way to programmatically create Persona Bar entries
The discovery that I made is that DNN can actually automatically create the Persona Bar entry (which for DNN 8 is a page under Admin) with just a few lines of metadata added to the .dnn manifest. These lines go into the <desktopModule> node of the module that needs to be added to the admin page.
<page type="Admin" common="true">
<description>Modify configuration settings for your site</description>
That's all! DNN takes care of creating the page for all portals during module installation. It also takes care of creating the page for newly created portals. This feature actually saves us hundreds of lines of code.
A bit of history
I couldn't find this feature documented anyway, so I dug up its history. Seems a lot of effort went into it. I found Issue DNN-7485 on DNN tracker that has very good documentation on intended use cases. I couldn't connect it to a particular commit, but to make sure it fits our purpose of being backwards compatible I downloaded DNN 8.0.0 source code and looked it up. And it was there. We plan to drop support for DNN 7 in January, so it looks like we'll use this feature a lot going forward.
Using the .dnn manifest approach makes it painless to create a custom administration page for a module. In DNN 9, it adds the entry in the Persona Bar under Manage section. On DNN 8, it creates the entry under Admin. There's also the option to add it under Host. The beauty of this approach is that requires very little code to manage and the entries are created for new portals as well.