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
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
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)
(and the file you need to copy is /concrete/blocks/form/controller.php)
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...?
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...?
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.
This way you don't have to copy everything if you just need to change one line in view() function.
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
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">
Viewing 15 lines of 60 lines. View entire code block.
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:
i.e. lines 140-215.
And you really need to put it inside the class brackets, not outside:
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 }
Hey look at that it works! fab, thank you :P
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
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
You probably need to copy more than just the controller.
Try copying the whole block folder.
Ben
Clear out your overrides cache and/or disable that when doing development.
All cache is turned off. and i have cleared just for good measure.
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.
Sorry to have wasted anyone's time.
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)
I always add a "reply to" line in here to use the email address of the person filling out the form by adding:
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.
(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.
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...
http://www.concrete5.org/documentation/how-tos/developers/overridin...
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:
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.
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.
System & Settings => Cache & Speed Settings => Disable "Overrides Cache" if it's on and then clear cache.
Best,
Antti / Mainio