Prevent errors when editing Page Type defaults

Prevent errors when editing Page Type defaults

Sometimes, when editing defaults for your custom page types you'll get errors which break your dashboard. Here's a fix.


Snippet by Ollie / / Comments / Difficulty 
Prevent errors when editing Page Type defaults

If you need to edit page type defaults on a custom page type, sometimes you'll find that code when not running in page collection context will produce errors. In extreme cases this can break your dashboard and prevent you editing properties and permissions for the page type itself.

This simple test will identify if you are viewing a master collection (page type), so you can branch your code appropriately and prevent those pesky errors.

$page = page::getCurrentPage();
if($page->isMasterCollection()) {
  echo "This is a page type";
} else {
  echo "This is a page";
}

Join the conversation

comments powered by Disqus