2

I have managed to override the magento's default contact us form, with additional fields and functionality and it seems to work.

The issue is when I disable my module in magento, my customised contact us form is shown instead of the default.

My assumption is that only if my module is active then my customisation (action methods and template) will available/displayed.

I think my issue is to do with overriding layout,block, template.

Some advice would be good.

Here's my code:

app/code/local/MyCompany/ContactsExtension/etc/config.xml

<config>
   <modules>
        <MyCompany_ContactsExtension>
            <version>0.1.0</version>  
        </MyCompany_ContactsExtension>
   </modules>
<frontend>
    <routers>
        <contacts>
            <args> 
                <modules> 
                    <MyCompany_ContactsExtension before="Mage_Contacts">MyCompany_ContactsExtension</MyCompany_ContactsExtension> 
                </modules> 
            </args> 
        </contacts>
    </routers>
</frontend>

<global>
    <blocks>
        <contactsextension>
            <class>MyCompany_ContactsExtension_Block</class>
        </contactsextension>
    </blocks>
   <helpers>
        <contactsextension>
            <class>MyCompany_ContactsExtension_Helper</class>
        </contactsextension>
    </helpers>           
</global>
</config>

Basically, I copied the default contacts.xml and added my changes. I think I may have not correctly updated it properly.

app/design/frontend/enterprise/mytheme/layout/contactsextension.xml

<layout version="0.1.0">
    <default>
        <reference name="footer_links">
            <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
        </reference>
    </default>

<contacts_index_index translate="label">
    <label>Contact Us Form</label>
    <reference name="head">
        <action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
    </reference>
    <reference name="root">
        <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
        <action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
    </reference>
    <reference name="content">
        <block type="core/template" name="contactForm" template="contactsextension/form.phtml">
            <block type="contactsextension/additionalfield" name="contacts.addfields" as="addfields" template="contactsextension/additionalfield.phtml" />
        </block>    
    </reference>
</contacts_index_index>
</layout>

Thanks, duniya.

2 Answers2

1

There are two ways to "disable" an extension, I put the word disable in quotes because one only disables the output. Depending on how you are currently disabling, make sure you try the other method too.

  1. In the admin area go to System > Configuration > Advanced > Advanced > Disable Module Output and select Disable for you extension. As it says, however, this will only disable the output. If your extension performs some other task, like observing an event, this will still continue.
  2. To fully disable the extension go to app/etc/modules/company_module.xml change the true to false in the tag:

    <config>
        <modules> 
            <company_module> 
                <active>true</active> 
                <codePool>local</codePool> 
            </company_module> 
    </modules> 
    

CCBlackburn
  • 1,704
  • 1
  • 12
  • 23
  • Thanks very much for your reply. However, I know how to disable modules in magento. However, my issue is to do with overriding core module. i.e when I disable my module, magento is still using my modified template for contact us instead of default template. If someone can check my config files that would be helpful. How should I override core module layout xml and template. Do I need to copy the contacts.xml layout and put it into my theme? Do I need to add something in the module config to enable layout file? Cheers – user1136431 Jan 08 '12 at 10:15
1

Yes, you need to define in your module config in the <frontend> section that you have layout updates like this:

<layout>
    <updates>
        <uniquehandle>
            <file>module_layout.xml</file>
        </uniquehandle>
    </updates>
</layout>

Then it should work properly when you disable your module. Otherwise Magento loads all layout updates found in layout folder of theme

Zifius
  • 1,650
  • 1
  • 16
  • 27
  • Thanks, makes sense. I previously tried this as I found another stackoverflow post about layout.xml I added layout update as you said. However, now when I load the contact us page in the browser, the form is show twice on the page. 2. if I disable the module in app/etc/modules/company_module.xml then it displayed default form. However, if I disable the module in admin, it uses my modified form. Any ideas? Also, what is the best way to override the layout xml. Should I copy contacts.xml into my theme, and make some changes. Is there any special tags I need to use in the copied file? Cheers. – user1136431 Jan 08 '12 at 23:50
  • I think you need to remove default form using `` directive to avoid duplication. For the second part of your question: disable module output doesn't disable processing layout instructions so you have to add additional check for this case using `ifconfig` instruction. Some insight here http://stackoverflow.com/questions/5596193/magento-xml-layouts-specify-value-for-ifconfig – Zifius Jan 09 '12 at 16:54