Nico: thanks, this looks interesting! Testing it right now, so might have more comments later, but first things first: you might want to add some isset-checks to module config. Seeing quite a few notices and warnings before saving module config.
Sorry, forget that, it's not about config. The problem is occurring in init(), when trying to check for $this->page->template. While viewing the module settings, $this->page doesn't seem to be available yet, which is causing some issues
Edit: here's a diff for changes I had to make locally to get this module running. Wouldn't work at all before that, possibly because I've got debug mode on. Not sure if they're all required, implemented the way you'd want them, etc. and some of them might be specific to my environment.
Also, moving the hooks from init() to ready() should ensure that API is ready by that time, but it could cause other (potentially unwanted) side-effects..
diff --git a/MarkupSEO.module b/MarkupSEO.module
index fecc6a3..c2ebb86 100644
--- a/MarkupSEO.module
+++ b/MarkupSEO.module
@@ -57,7 +57,7 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
* Initializing the hooks
*
*/
- public function init() {
+ public function ready() {
$this->addHookAfter("ProcessPageEdit::buildFormContent", $this, 'addSEOTab');
$this->addHookBefore("ProcessPageEdit::execute", $this, 'saveSEOTab');
@@ -85,9 +85,10 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
$page = wire('pages')->get($this->config->input->get->id);
$pageData = $this->getPageSEO($page->id);
$configData = wire('modules')->getModuleConfigData($this);
- $mixedData = array_merge((array)array_filter($configData), (array)array_filter($pageDataDefault));
+ $mixedData = array_merge((array)array_filter($configData), (array)array_filter($pageData));
+ $this->modules->get('FieldtypeFieldsetTabOpen');
$field = new InputfieldFieldsetTabOpen;
$field->name = $this->prefix."meta";
$field->label = $this->_('SEO');
@@ -158,6 +159,7 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
$e->return->add($field);
+ $this->modules->get('FieldtypeFieldsetClose');
$field = new InputfieldFieldsetClose;
$field->name = $this->prefix."meta_END";
@@ -204,7 +206,19 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
*/
private function getPageSEO($id) {
$dataOrg = wire('modules')->getModuleConfigData($this);
- return $dataOrg['pages'][$id];
+ if (isset($dataOrg['pages']) && isset($dataOrg['pages'][$id])) {
+ return $dataOrg['pages'][$id];
+ } else {
+ return array(
+ 'title' => '',
+ 'keywords' => '',
+ 'description' => '',
+ 'image' => '',
+ 'canonical' => '',
+ 'robots' => '',
+ 'custom' => '',
+ );
+ }
}
/**