Events::extendPageType() question

Permalink
Does this only apply to page types that are not created from a package? I have a package that installs a job, and that job should fire when on_page_add fires for a page type installed by the package. I have this in my page type's controller:

class 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.

hereNT
 
andrew replied on at Permalink Reply
andrew
That all strikes me as correct and doable. Yes, you should be able to use extendPageType exactly the way you're trying to do so.
andrew replied on at Permalink Reply
andrew
Have you added


<?php define('ENABLE_APPLICATION_EVENTS', true); ?>

to your config/site.php file ?
hereNT replied on at Permalink Reply
hereNT
I tried doing that but it didn't seem to make any difference. Events are happening, otherwise I wouldn't see the mobile version of the site when I look at it on my phone.

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?
andrew replied on at Permalink Reply
andrew
No - I think it's something else. The discussion add-on installs page types that have events and I just tested it and it appears to be firing.

Do the page types in the PageTypes table have the correct pkgID assigned to them?
hereNT replied on at Permalink Reply
hereNT
It looks like the package ids are set correctly. I just tried adding a new page type to the system and that seemed to work properly. Kind of pulling my hair out, I'm not sure why this isn't working.

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.
andrew replied on at Permalink Reply
andrew
What if you added some print statements to that file and then an exit, to make sure it's even hitting the file.
hereNT replied on at Permalink Reply
hereNT
I can do one better and step through with xdebug.

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.
andrew replied on at Permalink Best Answer Reply
andrew
tools is included before site_events.php, and when tools is done it exits.

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.
hereNT replied on at Permalink Reply
hereNT
I think rather than hacking dispatcher.php I'll just run the job when I create the page inside of the tools file - it's already doing enough stuff, might as well do one more. This seems easier from a code re-use standpoint, I want to use this package again on other sites without modifying the core...

Thanks for all your help on this, Andrew!
andrew replied on at Permalink Reply
andrew
Sure, no problem. As I mentioned, really the core ought to be able to handle this, and I think the reason it isn't is due to dispatcher load order. I'll tweak the order and maybe this will work in the future.