Fork me on GitHub
Current releases are 2.1.5 (31 Oct 2014) and 2.0.18.13 (5 Aug 2014)

Ready for 2.1? Find out if your plugins are compatible. 2.0 will no longer be updated after Dec 2014.

How do I extend the application controllers with my own methods?

edited June 2011 in Development
As I want to make an addition to the registration process.

I was planning on doing this by extending a couple of core files...

* applications\dashboard\views\entry\registerapproval.php
* applications\dashboard\controllers\class.entrycontroller.php

... in a custom theme:

* themes\[theme]\views\entry\registerapproval.php
* themes\[theme]\controllers\class.entrycontroller.php

The view file is great. It loads in, and I can see my changes.

But I don't know how to handle the controller, including:

* What folder to put it in
* The controller declaration (ie CustomEntryController X extends EntryController)
* Anything else I haven't mentioned here
* Whether this is even possible with this approach

My plan was to overload RegisterApproval() and check that the DiscoveryText was in fact the answer to a question I was going to ask in the view.

It's not a particularly MVC approach (I see there are rules that could be set in the model) but I don't know Garden / Vanilla well enough yet. I'm happy to try anything else as well (hooks/events/Machine Elves) as I prefer to do things properly.

Cheers,
Dave
Tagged:

Best Answer

  • ToddTodd Chief Product Officer Vanilla Staff
    edited June 2011 Answer ✓
    We actually have a way to block registrations with plugins specifically. Here's the code for your event handler:
    public function UserModel_BeforeRegister_Handler($Sender, $Args) {
    $User = $Args['User']; // Check this user...
    ...
    $Args['Valid'] = FALSE; // false blocks the registration
    }
    To answer your specific question, unfortunately you can't override the RegisterApproval method because it is not called through the dispatcher. You could override the Register method which is what you are going to anyway. You do this with the following event handler:
    public function EntryController_Register_Override($Sender, $Args) { ... }

Answers

Sign In or Register to comment.