Override core controllers in 5.6

Permalink 1 user found helpful
Hi I want to override the form block controller, this has always been easy to do without over writting the core files, however i cant seem to do it.

I've found the file /concrete/core/controllers/blocks/form_minisurvey.php

But if i put it here: /core/controllers/blocks/form_minisurvey.php
or here: /controllers/blocks/form_minisurvey.php

Neither affect it, is the only way to overwrite the system file?

(NB: The reason i want to do this is because i hate table based forms and want a div based form solution.)

Thanks

BHWW
 
Mainio replied on at Permalink Reply
Mainio
You probably have the overrides cache enabled:
System & Settings => Cache & Speed Settings => Disable "Overrides Cache" if it's on and then clear cache.

Best,
Antti / Mainio
Mainio replied on at Permalink Reply
Mainio
And one more note: that file should probably go to /blocks/form/controller.php

(and the file you need to copy is /concrete/blocks/form/controller.php)
BHWW replied on at Permalink Reply
BHWW
Thanks Mainio, all Caches are off.

and all that is in the new controller is:

<?php
defined('C5_EXECUTE') or die("Access Denied.");
class FormBlockController extends Concrete5_Controller_Block_Form {}
class FormBlockStatistics extends Concrete5_Controller_Block_FormStatistics {}
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {}

which is useless if you want to change anything...?
Mainio replied on at Permalink Reply
Mainio
No not really useless, it's better when you don't have to copy everything, just copy the function you need to modify under Concrete5_Controller_Block_FormMinisurvey class.

This way you don't have to copy everything if you just need to change one line in view() function.
BHWW replied on at Permalink Reply
BHWW
ok, ok so not useless yes ok. but in my opinion less user friendly... maybe i'll get used to it... but the difficulty here, is that before i could make adjustments without having to know how it all works. Now i need to know what 'function' i need to pull across.

i.e. if i pull out what i think i need i get an error and i have no idea where to start... your help would be greatly appreciated. Thanks

<?php  
defined('C5_EXECUTE') or die("Access Denied.");
class FormBlockController extends Concrete5_Controller_Block_Form {}
class FormBlockStatistics extends Concrete5_Controller_Block_FormStatistics {}
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {}
if(!$showEdit){
            echo '<div class="formBlockSurveyTable">';               
            while( $questionRow=$questionsRS->fetchRow() ){   
               if( in_array($questionRow['qID'], $hideQIDs) ) continue;
               // this special view logic for the checkbox list isn't doing it for me
               /*
               if ($questionRow['inputType'] == 'checkboxlist' && strpos($questionRow['options'], '%%') === false){
                  echo '<tr>
                          <td valign="top" colspan="2" class="question">
                            <div class="checkboxItem">
Mainio replied on at Permalink Best Answer Reply
Mainio
Yeah, the survey block in general is not the most coder-friendly. Maybe someone would say it's "slightly" outdated (having view stuff inside the controller).

Copy this whole function:
function loadSurvey( $qsID, $showEdit=false, $bID=0, $hideQIDs=array(), $showPending=0 ){
...
}


i.e. lines 140-215.

And you really need to put it inside the class brackets, not outside:
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {
  // PUT IT HERE
}
BHWW replied on at Permalink Reply
BHWW
Hey look at that it works! fab, thank you :P
Chrouglas replied on at Permalink Reply
I must be doing something wrong because I mimicked the process outlined in the post just to see if it would infact override and I don't see any of the test edits I made.

I opened concrete/core/blocks/form_minisurvey.php and copied the entire loadSurvey() function. Then copied concrete/blocks/form/controller.php to blocks/form/controller.php and pasted the loadSurvey() function into it like below

<?php
defined('C5_EXECUTE') or die("Access Denied.");
class FormBlockController extends Concrete5_Controller_Block_Form {}
class FormBlockStatistics extends Concrete5_Controller_Block_FormStatistics {}
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {


function loadSurvey( $qsID, $showEdit=false, $bID=0, $hideQIDs=array(), $showPending=0 ){

//loading questions
$questionsRS=$this->l.......... etc etc.

}

Just to test it out i changed the two lines that define the required variable... (* to TT)

$requiredSymbol=($questionRow['required'])?' <span class="required">TT</span>':'';

and nothing... still shows required items with a *


Any ideas what I am missing???? The thing that bugs me the most is that this isn't even what I am trying to accomplish. This is just a test to make sure that a function is being ovrridden. I actually just want to change the subject line of the email that is automatically sent out when the form is submitted to include either an input/text field supplied by a user or a select/option value selected by a user which would require overriding the core. So if anyone has input into how to accomplish any of the above pllease let me know.

Frustrated.
C
BHWW replied on at Permalink Reply
BHWW

You probably need to copy more than just the controller.

Try copying the whole block folder.

Ben
Mainio replied on at Permalink Reply
Mainio
Clear out your overrides cache and/or disable that when doing development.
Chrouglas replied on at Permalink Reply
All cache is turned off. and i have cleared just for good measure.
Chrouglas replied on at Permalink Reply
Thank you for your thoughts peeps. Today it hit me like a ton of bricks as to why the edits werent showing. I have been using a package that gives me tableless form layouts and that was overriding my overrides. So my changing the 'required' * to TT was just being changed back by the package's template file.

Sorry to have wasted anyone's time.
waynemoore replied on at Permalink Reply
Where would I find the code that builds the email header that used to be in concrete/blocks/form/controller.php starting on line 331

(see code snippet below)

$mh = Loader::helper('mail');
$mh->to( $this->recipientEmail ); 
$mh->from( $formFormEmailAddress );
$mh->addParameter('formName', $this->surveyName);
$mh->addParameter('questionSetId',$this->questionSetId);
$mh->addParameter('questionAnswerPairs', $questionAnswerPairs); 
$mh->load('block_form_submission');
$mh->setSubject(t('%s Form Submission', $this->surveyName));
//echo $mh->body.'<br>';
@$mh->sendMail();



I always add a "reply to" line in here to use the email address of the person filling out the form by adding:

$mh->replyto( $_POST['Question2'] );


I find that it is extremely common for my clients to hit reply when getting the form alert email from the website. Because I am usually the admin I get their reply instead of the person they are trying to reply to, adding this line fixes that problem and makes my clients happy.
timtorres replied on at Permalink Reply
timtorres
I've come across the same problem and found an official answer here but haven't tried it yet.
http://www.concrete5.org/documentation/how-tos/developers/overridin...
kspitzley replied on at Permalink Reply
kspitzley
Just a note since I spent way too much time trying to figure something very similar out and finally succeeded. Maybe this will help someone else out.

I wanted to override the core date nav controller from a custom template so that it would sort by a custom date attribute. I found the core date_nav controller in concrete=>core=>controllers=>blocks=>date_nav.php. I copied the function that containined the sortBy code and pasted it in my custom template's controller.php file and changed the sortBy part of the function like this:

class DateNavBlockController extends Concrete5_Controller_Block_DateNav {
function getPages($query = null) {
//blah blah blah
$pl->sortBy('my_custom_attribute', 'desc');
//blah blah blah
}
}


Then I loaded my newly edited controller.php file to blocks=>date_nav.

I wasted some time loading the controller.php file to blocks=>date_nav=>templates=>my_template.