Events::extendPageType() question
Permalinkclass HutmanEventPageTypeController extends Controller { public function on_page_add($c) { Loader::model('job'); $job = Job::getJobObjByHandle('archive_event_items'); $job->executeJob(); } }
And then this inside of my site_events.php:
Events::extend('on_start', 'ThemeSwitcher', 'checkForIphone', 'libraries/theme_switcher.php'); Events::extendPageType('hutman_event');
Events appear to be working fine otherwise, the browser sniffer for mobile devices works and switches out the theme, I just can't figure out why my job doesn't run when I add a page. The job runs fine when run from "System & Maintenance" so I know it's not a problem there, it's that the event is not firing for the page type.
Any help would be appreciated.

<?php define('ENABLE_APPLICATION_EVENTS', true); ?>
to your config/site.php file ?
I think the only thing I can really do to test further would be to create another page type that _isn't_ from inside a package with it's own controller and see if that works?
Do the page types in the PageTypes table have the correct pkgID assigned to them?
I guess worse case scenario I can just have the client run the job manually from the dashboard, it just seemed much more elegant to do it when you add or update a page. I think when I first started it I was trying to get it to fire on_page_version_approve and I switched to on_page_add because that wasn't working.
Hrm.
It looks like this is a little more involved - if I add the page from the site map or the front end, then it works just fine. I'm trying to add them via code from a tools file for the news and events addons I was mentioning to you yesterday. Apparently that does not fire the event?
This is what it looks like to add the page via the tools file, it seems pretty straightforward to me, but I guess it won't work to do what I'm trying to do:
$cParent = Page::getByID($form['cParentID']); Loader::model("collection_types"); $ct = CollectionType::getByHandle('hutman_event'); $data = array('cName' => $form['title'], 'cDescription' => stripTags($description)); $eventPage = $cParent->add($ct, $data);
I think I ran into something similar with on_page_delete(), that one doesn't fire from the dashboard site map, only from the front end page move/delete panel.
So my guess here is that what I'm trying to do is impossible? I could maybe make a custom event and fire it when the page is added, or run my job from the tools file that is adding the page, but I don't think I'm going to be able to use the events system for this.
I don't see any problem with including site_events.php BEFORE tools. You can try this out yourself, by opening dispatcher.php and finding the site_events.php include section and moving it directly above the tools section. In the github version of concrete5 it is right below it.
Thanks for all your help on this, Andrew!