Jump to content

Recommended Posts

Martin: Thanks!

Ryan: what would be best approach, if I would like to create sitemap for AdminBar? Or any other "customized" page?

My initial plan is this:

Check if there is template called "AbminBarPage"

->if not, create template (title & body fields)

Check if there is page /adminbar/sitemap/

-> if not, create page

-> put needed code into body

It would be probably good idea to actually produce each view as AdminBarPage, then this module wouldn't break on changes on admin templates (or if some site has custom admin etc).

Share this post


Link to post
Share on other sites

These are just thoughts, but my first idea was that it would provide full site map (well, maybe not full if there is very deep levels..) in open state, show clearly where the current page is. Then of course links to move to other pages. Probably no need to edit, move etc (since these are easily done through real admin).

In short: to provide quick look over the whole site and where the current page is.

Share this post


Link to post
Share on other sites

I made some progress here.

Most important thing first: PW source is very well documented and it just makes sense! After half an hour I started guessing method names and usually got them always right :P

I have now version working, where I create adminbar-template (with fieldgroup & title field), adminbar-templatefile & and finally create the page. I'm not sure if this is right way to go, but I see huge benefits this way:

  • Template-files that adminbar uses goes to site/templates/adminbar folder, so they are easily customized per site basis
  • We could have ie. "Information for content editors" field that is showed everyone who is editing content etc. Maybe more settings per different view etc?
  • This gives full control to create modal views as I like them to be - easier to develop than hooking. Of course there we have to be careful not to re-invent the wheel and keeping UI consistent with other aspects of PW

Only negative things I can think of now are

  • More templates, more pages, more templatefiles...
  • But probably just a good thing, if those can be visible only to superadmins (I don't know yet how UA works)

This was quick hack, but if Ryan confirms that this is not worst way of developing AdminBar further, I'll probably go forward and implement this at least on the views that current admin doesn't provide (I know correctly this means only the "full sitemap view" so far).

Share this post


Link to post
Share on other sites

re: content editors: just a note: as Ryan previously stated, everything about Users [user roles, intercommunication, data information, versioning] is mostly in very crude, unpolished state – because Pages and overall API had hightest priority. Therefore, for few things there are no solutions currently [who's editing what, etc]

Share this post


Link to post
Share on other sites

I have it working nicely... almost :) One little problem that I cannot figure out. For some reason this code gives me HTTP-error 500, but only once (first time it runs). Probably some silly error (I create stuff on wrong order or something similar..? Or save() doesn't return the object I assume it returns? Ryan, any ideas what I am doing wrong?

I have also attached full module if anyone is interested to try. There is one new feature and it is quick collapse-enabled sitemap to show where the current page is located and to quickly move around your site.

I know this code could be cleaned up a lot, but be gentle - I am just learning this stuff :)

private function _createAdminBarPages() {
	$abName = "adminbar";
	$abFieldGroup = $this->fieldgroups->get($abName);
	$abTemplate = $this->templates->get($abName);
	$abPage = $this->pages->get("/processwire/{$abName}/");

	if(is_null($abFieldGroup))
		$abFieldGroup = $this->_createAdminBarFieldGroup($abName);

	if(is_null($abTemplate))
		$abTemplate = $this->_createAdminBarTemplate($abName, $abFieldGroup);

	if(!file_exists($abTemplate->filename()))
		$this->_createAdminBarTemplateFile($abTemplate);

	if(!$abPage->id)
		$abPage = $this->_createAdminBarPage($abName, $abTemplate);

}

private function _createAdminBarFieldGroup($fieldGroupName) {
	$abFieldGroup = new Fieldgroup();
	$abFieldGroup->name = $fieldGroupName;
	$abFieldGroup->add("title");
	return $abFieldGroup->save();
}

private function _createAdminBarTemplate($templateName, $abFieldGroup) {
	$abTemplate = new Template();
	$abTemplate->name = $templateName;
	$abTemplate->setFieldgroup($abFieldGroup);
	return $abTemplate->save();
}

private function _createAdminBarPage($abName, $abTemplate) {

	// create /adminbar/ page under admin
	$abPage = new Page();
	$abPage->template = $abTemplate;
	$abPage->parent = $this->pages->get("/processwire/"); // TODO: How to remove hardcoding admin url??
	$abPage->title = $abName;
	$abPage->name = $abName;
	$abPage->status = 1031; // hidden & locked
	$abPage->save();

	// after that create /adminbar/adminbpar-sitemap/
	$abSitemapPage = new Page();
	$abSitemapPage->template = $abTemplate;
	$abSitemapPage->parent = $abPage;
	$abSitemapPage->title = $abName . '-sitemap';
	$abSitemapPage->name = $abName . '-sitemap';
	$abSitemapPage->status = 1031;
	return $abSitemapPage->save();
}

private function _createAdminBarTemplateFile($abTemplate) {
	copy(dirname(__FILE__)."/pages/sitemap.php", $abTemplate->filename());
}

AdminBar.zip

Share this post


Link to post
Share on other sites

Apeisa,

I tried this out and it works great! Nice work. The site map view is very useful too. Also, I think the code looks good! Here's a few suggestions and notes I've got:

The 500 error you got was thrown by ProcessWire. The problem is these lines:

return $abFieldGroup->save();
return $abTemplate->save();

All the save functions return a result status, basically true if it was successful, false if not. So to fix the error, you would need to change lines like the above to:

$abFieldGroup->save();
return $abFieldGroup;

$abTemplate->save();
return $abTemplate; 

When you are developing in ProcessWire, you may want to enable debug mode, so that errors are echoed to the screen. You can turn this on in /site/config.php. Look for the line that says $config->debug = false; and change it to true.

Next, I wanted to mention that the module interface provides install() and uninstall() methods, in case you want them:

/**
* Perform any installation procedures specific to this module, if needed. 
* 
* This method is OPTIONAL
*
*/
public function ___install();

/**
* Perform any uninstall procedures specific to this module, if needed. 
*
* This method is OPTIONAL
*
*/
public function ___uninstall();

There may be issues on many installations with your last function, _createAdminBarTemplateFile. The reason is that ProcessWire doesn't usually have write access to the templates dir (it depends on the server). So your installer may be want to look for this, or advise them to copy your template file in there if there isn't write access. Or, we could just make it a blank template (without a file) and then hook into it's render method so that your .module file can render the output instead. Let me know if you want to do that, and I can provide instructions.

Lastly, because the site map outputs a full sitemap, it may not scale to large installations. For instance, the site I am working on now has 5k+ pages, and while it renders them all, it takes several seconds. :) But on large installations, it might just run out of memory too. As a result, I would recommend placing a limit to the number of subpages that the sitemap will display. Maybe a "limit=50" per branch, just to account for the possibility of large sites. And once it reaches that limit, it might have a label that says "Go to the admin to view remaining pages" or something like that.

Again nice work on this, I am really enjoying using this module!

Share this post


Link to post
Share on other sites

Ryan, thanks for your answer. I wasn't sure about the write access on template dir (I develop on windows when there is basicly always write access).

So your installer may be want to look for this, or advise them to copy your template file in there if there isn't write access. Or, we could just make it a blank template (without a file) and then hook into it's render method so that your .module file can render the output instead. Let me know if you want to do that, and I can provide instructions.

Hmm.. I think that the latter is better. Or maybe both? If there is template file -> use that. If not -> render. Is that possible? The first reason I went for this "copy template file" route was that I didn't know any other way to make this work :)

Share this post


Link to post
Share on other sites

I think it might be better to just override the template rather than putting one in the /templates/ dir (unless you want to encourage them to edit it). I've modified the Template class so that you can change the target filename at runtime, so you'll want to grab the latest commit.

https://github.com/ryancramerdesign/ProcessWire/commit/0c8dc7d8e62c9a6a110791e00111c463ff00b01c

Next, move that template to the same directory as your module (/site/modules/AdminBar/adminbar.php).

Then in your AdminBar.module, add a new "before" page render hook. It will check to see if the page template is "adminbar", and if it is, it'll change the template filename to the one in your /site/modules/AdminBar/ dir.

<?php
public function beforePageRender($event) {
    $page = $event->object;
    if($page->template == 'adminbar') {
        $page->template->filename = $this->config->paths->AdminBar . "adminbar.php";
    }
}

Also, add this to your init() function in AdminBar.module:

$this->addHookBefore('Page::render', $this, 'beforePageRender');

If you do decide you want it to check if the file is in your /site/templates/ first, then just add that check to your beforePageRender method.

Now it should work exactly the same as before, except that it'll use the template file in your /site/modules/AdminBar/ dir rather than expecting one to be in /site/templates/.

Share this post


Link to post
Share on other sites

Lastly, because the site map outputs a full sitemap, it may not scale to large installations. For instance, the site I am working on now has 5k+ pages, and while it renders them all, it takes several seconds. :) But on large installations, it might just run out of memory too. As a result, I would recommend placing a limit to the number of subpages that the sitemap will display. Maybe a "limit=50" per branch, just to account for the possibility of large sites. And once it reaches that limit, it might have a label that says "Go to the admin to view remaining pages" or something like that.

I created this functionality and noticed that $page->numChildren gives num of all children (hidden also). Is there some selector that I can use to count only visible children?

Share this post


Link to post
Share on other sites

Well.. there is small bug. After deleting a page we get this error:

Call to a member function isAjax() on a non-object (line 62 of C:\apache\htdocs\pw\wire\core\admin.php)

This error message was shown because you are logged in as a Superuser.

This must be because of modal somehow? Deleting pages sends them to thrash (so it works), but we still get that error. I could just disable delete-tab on modal, but I think that is a nice feature. Any clues on this one Ryan?

Share this post


Link to post
Share on other sites

I should sort it out for IE, finally. But, unfortunately, no time :( I should also style that hide link a little {maybe another glyph?}

good work Antti.

Share this post


Link to post
Share on other sites

I should sort it out for IE, finally. But, unfortunately, no time :( I should also style that hide link a little {maybe another glyph?}

good work Antti.

Thanks Adam. And no reason for stress because of this, early days and most important thing is to learn module dev.

If someone has plans to use this on client site then please us know and we'll fix the "browser".

Share this post


Link to post
Share on other sites

I created this functionality and noticed that $page->numChildren gives num of all children (hidden also). Is there some selector that I can use to count only visible children?

There is. Try this:

$total = $page->children("limit=2")->getTotal();

You have to do "limit=2" (or higher) rather than "limit=1" because PW2 doesn't currently count totals on limit=1 selectors. That's just as a matter of efficiency, since all $pages->get() functions use limit=1 internally.

Share this post


Link to post
Share on other sites

This must be because of modal somehow? Deleting pages sends them to thrash (so it works), but we still get that error. I could just disable delete-tab on modal, but I think that is a nice feature. Any clues on this one Ryan?

I'm not sure why that error was turning up, and am out of time to take an in-depth look, but I was able to fix it easily. And actually I think it's something I should have had in there in the first place (an extra check to make sure that $controller is not null), so thank you for finding it. :) I have fixed this in the latest commit:

https://github.com/ryancramerdesign/ProcessWire/commit/99454cb68b0ccfe287ab82c68c9db7010a6f94be

AdminBar is looking great! Would you mind if I tweeted a link to your screencast?

Share this post


Link to post
Share on other sites

Updates: IE is fucking nightmare:


  •  
  • minor updates on github
     
  • still old readme [wanted to do the markdown version, no chance
     
  • IE7 isn't supported even by the PW Admin, no prob there [iE6 wasn't even tried]
     
  • IE8 is doing something funky with z-index, so hover doesn't work. I solved the width, but this is killing me. Also, BG of overlay isn't showing (because IE8 doesn't know rgba colors)
     
  • IE9 can't be virtualized in XP, and I don't have Win7 virtualized currently [neither install CD]. Also, IE9 is beta, so no hard feelings there

This should be it, I might look on the site tree later on too, because it's fugly.

Also I'm pissed, nothing works tonight. Good night, more updates tomorrow or later.

Share this post


Link to post
Share on other sites

I'm not sure why that error was turning up, and am out of time to take an in-depth look, but I was able to fix it easily. And actually I think it's something I should have had in there in the first place (an extra check to make sure that $controller is not null), so thank you for finding it. :) I have fixed this in the latest commit:

https://github.com/ryancramerdesign/ProcessWire/commit/99454cb68b0ccfe287ab82c68c9db7010a6f94be

AdminBar is looking great! Would you mind if I tweeted a link to your screencast?

Thanks for the fix. And sure you can tweet the screencast.

Share this post


Link to post
Share on other sites

I merged Adam's changes to adminbar. Also took cleaning further: I removed other options than modal and also cleaned js & css even more. It should work in IE now (I have only IE9 on my home computer and it works on that now. I am pretty confident that it works ok in other IE:s too - but no promises here :)).

Reasoning for taking options out: I think shortcuts will be the actual view that everyone uses: editing & creating will be done there. "Main" view will be for looking more information: who edited and when etc (hope to make that better later). And I think admin link should always take to admin front.

Also: I think this as real 1.0 release. I'll fix all the bugs that people may a rise, but any new features will be added with care. Of course all the optimizing to code and UI are most welcome (from Adam or anyone who is interested in contributing).

Share this post


Link to post
Share on other sites

I receive error when installing:

Exception: Can't save page 0: /adminbar/: It has no parent assigned (in www\phreshr.tv\wire\core\Pages.php line 337)

#0 [internal function]: Pages->___save(Object(Page))

#1 www\phreshr.tv\wire\core\Wire.php(241): call_user_func_array(Array, Array)

#2 www\phreshr.tv\wire\core\Wire.php(203): Wire->runHooks('save', Array)

#3 www\phreshr.tv\wire\core\Page.php(733): Wire->__call('save', Array)

#4 www\phreshr.tv\wire\core\Page.php(733): Pages->save(Object(Page))

#5 www\phreshr.tv\site\modules\AdminBar\AdminBar.module(312): Page->save()

#6 www\phreshr.tv\site\modules\AdminBar\AdminBar.module(284): AdminBar->_createAdminBarPage('adminbar', Object(Template))

#7 ww

This error message was shown because you are logged in as a Superuser.

Any suggestions on whats wrong? It had worked briefly. Then all of a sudden it didn't. I'm on a wamp stack and using php 5.3.5.

Share this post


Link to post
Share on other sites

Thanks for trying AdminBar and sorry for problems.

Error is probably that I have hardcoded the /processwire/ site as admin site. If you have renamed your admin (so that url is not /processwire/), then it will fail like that. You can make quick fix by editing two lines (chance them to have your admin page url):

https://github.com/apeisa/AdminBar/blob/master/AdminBar.module#L275

https://github.com/apeisa/AdminBar/blob/master/AdminBar.module#L308

I'll take a look how I could remove that hardcoding later today (I tried that earlier, but didn't work - Ryan, any clues? Probably some silly typo I had there...).

Share this post


Link to post
Share on other sites

You can get the admin URL from:

$config->urls->admin

Or if you want to retrieve the admin page:

$admin = $pages->get($config->adminRootPageID); 

Btw, I don't often do it, but it is good security to change your admin page name. You do this by editing it, clicking on the 'settings' tab and changing the name.

Share this post


Link to post
Share on other sites

Btw, I don't often do it, but it is good security to change your admin page name. You do this by editing it, clicking on the 'settings' tab and changing the name.

Heh, I made this and got redirect to 404. I thought it was somehow because of AdminBar.. but it wasn't. Spend few minutes itching my head and disabling all redirects on AdminBar.module... :)

Thanks for the tips Ryan. Now AdminBar works with any admin url, latest files are on GitHub.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...