Skip to content

Instantly share code, notes, and snippets.

@outflux3
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outflux3/cf5807ddedfaa5c0d425 to your computer and use it in GitHub Desktop.
Save outflux3/cf5807ddedfaa5c0d425 to your computer and use it in GitHub Desktop.
Processwire Append Other Page Body
<?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