Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Concrete Wall for #concrete5 -- Integration of the core discussion forums addon. This adds wall postings when a user creates a new discussion or replies to an existing one. Add this code anywhere that gets run on every request -- /config/site_events.php is a good place.
// register event so that our SiteDiscussionWallPoster::hookPageAdd() gets called when pages get added
Events::extend('on_page_add', 'SiteDiscussionWallPoster', 'hookPageAdd', false);
class SiteDiscussionWallPoster {
* gets called when on_page_add event is fired. adds a wall posting if page of type "discussion_post" was added
* @param Page $page page object that was added, passed in by event model
public function hookPageAdd(Page $page) {
//this is a discussion_post page
if ($page->getCollectionTypeHandle() == 'discussion_post') {
$wall = Loader::package('lerteco_wall');
$u = new User();
//both the main thread and all replies are of type 'discussion_post'
// we want to treat the main thread and replies differently, so we create two different posting types
// also, we pass the main thread ID to both
$parent = Page::getByID($page->getCollectionParentID());
if ($parent->getCollectionTypeHandle() != 'discussion_post') {
//parent page type is NOT discussion_post. we're not a reply
$posting_type = array('discussion', 'discussion_post_new', 'New Post', 'posted %1$p', 1, PostingType::SHAREWITH_ALL);
$wall->postAndPossiblyRegister($u->getUserID(), $page->getCollectionID(), $posting_type);
} else {
//the parent is a discusson_post, too, which means this is a reply
$posting_type = array('discussion', 'discussion_post_reply', 'Reply', 'replied to %1$p', 1, PostingType::SHAREWITH_ALL);
$wall->postAndPossiblyRegister($u->getUserID(), $parent->getCollectionID(), $posting_type);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment