4

Using the Pixel & Tonic Contact Form plugin, I added a config file (config/contactform.php) to override plugin settings from the CP.

I would like to change some settings if devMode is enabled : recipients from the contact form plugin, to separate my tests addresses from my client addresses.

<?php

$recipients = array(
    'devMode' => 'example@domain.com,example@domain.com',
    'prodMode' => 'john@doe.com,jean@dupont.com'
);

if (devMode == true) {
    $recipients = $recipients['devMode'];
} else {
    $recipients = $recipients['prodMode'];
}

return array(
    'toEmail' => ($recipients ?: null),

How can I check if devMode == true? Can I access to this value using craft()->config or something else that?

7

It's as simple as

if ( craft()->config->get( 'devMode' ) )
{
 //do stuff
}
  • Using this, I get this error : The property « Craft\ConfigService.devMode » is undefined.. Yes, I'm using environment variables, but following the other answer there is no devMode data that I can get from the craft()->config->get('environmentVariables'), while devMode is enabled in my current dev environment. – Romain Poirier Jun 29 '16 at 8:34
  • This is because you're not in the Craft namespace. Included in most files is a namespace Craft; declaration at the top of the file, but in config files this is not usually there. You could either add this namespace declaration to your config file, or use \Craft\craft()->config->devMode instead. – Ben Fleming Jun 29 '16 at 8:37
  • namespace Craft; was already specified at the first line of my config/contactform.php file. – Romain Poirier Jun 29 '16 at 8:39
  • Ok, I found the solution : craft()->config->get('devMode') does the job. Thank you ! – Romain Poirier Jun 29 '16 at 8:41
  • 2
    Oh I see, I misread the original error. I'm pretty sure you need to use craft()->config->get('devMode') instead – Ben Fleming Jun 29 '16 at 8:41
8

For those coming here using Craft 3, it's now Craft::$app->getConfig()->general->devMode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.