We've had issues with AdminBar loading in admin context. This is especially harmful when dealing with PageTable field, as the JavaScript redirect pretty much renders this module unusable (or PageTable unusable, depending on your point of view).
@@ -13,7 +13,7 @@
'title' => 'Admin Bar',
'summary' => 'Fast and easy in-page content editing',
'href' => 'http://processwire.com/talk/index.php/topic,56.0.html',
- 'version' => 101,
+ 'version' => 102,
'permanent' => false,
'autoload' => true,
'singular' => true,
@@ -52,6 +52,12 @@
}
/**
+ * Permission required by our module
+ *
+ */
+ protected $ab_permission;
+
+ /**
* Initialize the module and setup hooks
*
* The init method of a module is called right after ProcessWire is bootstrapped, when all
@@ -74,15 +80,28 @@
if ($this->user->isGuest()) return false;
- $ab_permission = $this->permissions->get('adminbar');
- if(!$this->user->hasPermission($ab_permission)) return false;
+ $this->ab_permission = $this->permissions->get('adminbar');
+ if(!$this->user->hasPermission($this->ab_permission)) return false;
+ // hook before forms are rendered, so that we can modify the form's "action" attribute
+ $this->addHookBefore('InputfieldForm::render', $this, 'formRender');
+ }
+
+ /**
+ * Setup rest of the hooks
+ *
+ * Some hooks have to be defined here, since we need access to $page var.
+ *
+ */
+ public function ready() {
+
+ if ($this->user->isGuest() || ($this->page && $this->page->template == "admin")) return false;
+
+ if(!$this->user->hasPermission($this->ab_permission)) return false;
+
$this->pages->addHookAfter('save', $this, 'pageSave');
$this->addHookAfter('Page::render', $this, "pageRender");
- // hook before forms are rendered, so that we can modify the form's "action" attribute
- $this->addHookBefore('InputfieldForm::render', $this, 'formRender');
-
// hook before a redirect occurs, os we can modify the redirect URL
$this->session->addHookBefore('redirect', $this, 'sessionRedirect');
}
What do you think, would this be valid solution, and could the module be updated to this? Any better ideas? I was going to add a check to JS first, but this seems to work much better -- unless there's some reason to load AdminBar in admin context, that is..
Module.php claims that init() is "required", but so far this seems to work perfectly without it too.. might be something that has changed since then, but to guarantee backwards compatibility, empty init() method should probably be added.. and comments should definitely be updated too :)