Magento – How to add the WYSIWYG editor in customer form in admin area

customer-attributemagento-1.9PHPwysiwyg

i create a custom attribute in customer form,that is textarea, in that i need to add the WYSIWYG editor.

enter image description here

your suggestion and idea will help me more

Best Answer

Here is what worked for me.
First of all, the attribute education must have the frontend_input set to editor. If you already have the attribute change the value of the frontend_input column in the eav_attribute table to editor.
If you are willing to start from scratch here is a full module that worked for me.
Let's call the module StackExchange_Education.
You will need the following files.

app/etc/modules/StackExchange_Education.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Education>
            <active>true</active>
            <codePool>local</codePool>
            <depends><Mage_Customer/></depends>
        </StackExchange_Education>
    </modules>
</config>

app/code/local/StackExchange/Education/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Education>
            <version>1.0.0</version>
        </StackExchange_Education>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <customer_edit_tab_account>StackExchange_Education_Block_Adminhtml_Customer_Edit_Tab_Account</customer_edit_tab_account><!-- rewrite the account edit block -->
                </rewrite>
            </adminhtml>
        </blocks>
        <resources>
            <stackexchange_education_setup><!-- setup resource for adding the attribute -->
                <setup>
                    <module>StackExchange_Education</module>
                    <class>Mage_Customer_Model_Resource_Setup</class>
                </setup>
            </stackexchange_education_setup>
        </resources>
    </global>
    <adminhtml>
        <layout>
            <updates>
                <stackexchange_education>
                    <file>stackexchange_education.xml</file><!-- layout file for enabling the editor -->
                </stackexchange_education>
            </updates>
        </layout>
    </adminhtml>
</config>

app/code/local/StackExchange/Education/sql/stackexchange_education_setup/install-1.0.0.php - the install script that adds the attribute. If you already have the attribute and you just change the frontend_input to editor you don't need this

<?php
$this->addAttribute('customer', 'education', array(
    'type'      => 'text',
    'label'     => 'Education',
    'input'     => 'editor',
    'position'  => 120,
    'required'  => false,//or true
    'is_system' => 0,
));
$attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'education');
$attribute->setData('used_in_forms', array(
    'adminhtml_customer',
));
$attribute->setData('is_user_defined', 0);
$attribute->save();

app/code/local/StackExchange/Education/Block/Adminhtml/Customer/Edit/Tab/Account.php - the rewrite of the admin account block

<?php
class StackExchange_Education_Block_Adminhtml_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{
    public function initForm()
    {
        parent::initForm();
        $form = $this->getForm();
        $educationElem = $form->getElement('education');
        $educationElem->setConfig(Mage::getSingleton('cms/wysiwyg_config')->getConfig());
        return $this;
    }
}

app/design/adminhtml/default/default/layout/stackexchange_education.xml - the layout file for enabling the editor

<?xml version="1.0"?>
<layout>
    <adminhtml_customer_edit>
        <update handle="editor" />
        <reference name="head">
            <action method="setCanLoadTinyMce"><load>1</load></action>
        </reference>
    </adminhtml_customer_edit>
</layout>

Clear the cache and give it a try.