How to override Email module file

Hello Folks,

I have make change send method of email module and I want to make it upgrade_safe with override the file. For that I have changed the file modules/Emails/Email.php and for override I have put it to custom/modules/Emails/Email.php but this file is not calling.

Then I have changed the file path from modules/Emails/Email.php to custom/modules/Emails/Email.php in file include/modules.php and include/utils.php but it show error “PHP Fatal error: Cannot declare class Email, because the name is already in use”. Please help me regarding this issue.

When making changes to core modules it is better to use ‘custom’ folder.

The ‘include/modules.php’ should not be changed so here is what i would do for your particular problem:

From the root directory of your CRM instance navigate to custom/Extension/application/Ext/Include

Inside the folder create a new php file, call it suitecrm-emails.php

Inside write the following:

$beanList['Emails''] = 'CustomEmails';
$beanFiles['CustomEmails'] = 'custom/modules/Emails/Emails.php';

Save the file and go into the Emails.php inside the custom folder.
Change the class name from Emails to CustomEmails and extend the original Emails class

class CustomEmails extends Emails {}

Navigate to Administration->Repair and do a Quick Repair and Rebuild

But there is an issue which requires the modification of Core CRM SugarBean file.
When creating the above extended class all CUSTOM FIELDS will not load because we changed the object name and only the core module fields will work.
There is a workaround but requires you to navigate to ‘modules/DynamicFields/DynamicField.php’ and go to function ‘saveToVardef’ inside after the following code

$object = BeanFactory::getObjectName($module);

Insert this:

if($object === 'Custom' . $module ){
        $object = $module;

so it then looks like this :

$object = BeanFactory::getObjectName($module);
if($object === 'Custom' . $module ){
   $object = $module;

Hope it helps.

1 Like

Hello zan1515,
Is it possible to override include\SearchForm\SearchForm2.php?

Hi jrawoot,

Depends on what you want to do.

If you only want to change how it handles in ListView then you can extend the view.list.php where it calls the SearchForm class.

The problem is it is referenced on multiple files as ‘require’ so you would need to modify the core file SearchForm2.

If i find an other path to solving your issue i will write to you.

Hope it helps

Hello @zan1515 ,
I don’t know if you can help me but reading the previous posts I have a slightly different problem… I’m supposed to secure a change to a core file for updates.
Specifically I followed a PGR post to modify the global search.
This example works, but the modification to the file
I would like to make it secure for future updates. I tried to find out how to extend the core functionality… but almost all posts talk about module extensions… the Home module I don’t know if it can be extended… especially the ‘search()’ method of the ‘UnifiedSearchAdvanced’ class.
Have you already had similar experiences?


The example I followed is

Hey, @web_elinet

So i checked where the UnifiedSearchAdvanced is referenced and it is used in quite a lot of files.

The problem is it is using require_once hardcoded path to the file. Because of this i dont think there is a secure way of extending it.

1 Like

As I suspected :sob:.
Thanks anyway.