Last active
August 29, 2015 14:07
-
-
Save outflux3/cf5807ddedfaa5c0d425 to your computer and use it in GitHub Desktop.
Processwire Append Other Page Body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AppendBoilerplates extends WireData implements Module { | |
/** | |
* Basic information about module | |
*/ | |
public static function getModuleInfo() { | |
return array( | |
'title' => 'Append Boilerplates', | |
'summary' => 'Append selected boilerplate texts to a text body', | |
'href' => '', | |
'version' => 001, | |
'permanent' => false, | |
'autoload' => true, | |
'singular' => true, | |
); | |
} | |
/** | |
* Populate the default config data | |
* | |
*/ | |
public function __construct() { | |
} | |
/** | |
* Initialize the module and setup hooks | |
*/ | |
public function init() { | |
$this->pages->addHookAfter('saveReady', $this, 'AppendBoilerplates'); | |
} | |
/** | |
* | |
* @param HookEvent $event | |
*/ | |
public function AppendBoilerplates(HookEvent $event) { | |
// Accesses the $page object | |
$page = $event->arguments[0]; | |
//if(!$page) return; | |
if($page->template != 'email') return; | |
$body = $page->body; | |
if($page->boilerplate_select->count()) { | |
foreach($page->boilerplate_select as $bp) { | |
$body .= '<hr>' . $bp->body; | |
$page->boilerplate_select->remove($bp); | |
$page->save(); | |
$this->message("{$bp->title} inserted and removed from selected boilerplates"); | |
} | |
} | |
$page->body = $body; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment