1

I am using below code in a custom module but when I want to use the Insert/Edit image --> Browse then I get a popup with a 404 of my frontend site.

    $configSettings = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
        array(
        'add_widgets' => false,
        'add_variables' => false,
        'add_images' => false,
        'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/',
    )); 

    $fieldset->addField('kb_article_content', 'editor', array(
        'label'     => Mage::helper('support')->__('Article Content'),
        'title'     => Mage::helper('support')->__('Article Content'),
        'required'  => true,
        'name'      => 'kb_article_content',
        'style'     => 'width:700px; height:500px;',
        'wysiwyg'   => true,
        'config'        => $configSettings,
    ));

2

I got the same issue while working with the third-party code. I needed to add wysiwyg field and image upload didn't work.

The issue in my case happened because module admin pages used domain.com/module_admin_route/controller/action, while magento admin controllers use domain.com/admin_path/module_admin_route/controller/action. admin_path is just your regular path for admin panel, default is admin.

In normal case, image upload window is loaded via ajax request from Mage_Adminhtml_Cms_Wysiwyg_ImagesController. As you can see, this controller isn't located under Cms module, but rather under Adminhtml module. The URL for this request is then admin/cms_wysiwyg_images/index.

For some reason magento assumes that you are on magento admin route, and uses current route to create url for ajax request, which results in module_admin_route/cms_wysiwyg_images/index which most likely doesn't exist in your module, hence 404.

There are probably many ways to solve it, but I found in the same module solution for the other wysiwyg field. Basically, they just find every occurrence of module_admin_route and replace it with default admin route:

(in your Field.php)

try {
        $config = Mage::getSingleton('cms/wysiwyg_config')->getConfig();
        $config->setData(
            Mage::helper('module')->recursiveReplace(
                '/module_admin_route/',
                '/' . (string)Mage::app()->getConfig()->getNode('admin/routers/adminhtml/args/frontName') . '/',
                $config->getData()
            )
        );
    } catch (Exception $ex) {
        $config = null;
    }

$fieldset->addField(
        'description',
        'editor',
        array(
             'name'  => 'description',
             'label' => Mage::helper('module')->__('Description'),
             'title' => Mage::helper('module')->__('Description'),
             'wysiwyg'   => true,
             'style'  => 'width:800px; height:500px;',
             'config' => $config,
        )
    );

This helper method just recursively follows config array:

public function recursiveReplace($search, $replace, $subject)
{
    if (!is_array($subject)) {
        return $subject;
    }

    foreach ($subject as $key => $value) {
        if (is_string($value)) {
            $subject[$key] = str_replace($search, $replace, $value);
        } elseif (is_array($value)) {
            $subject[$key] = self::recursiveReplace($search, $replace, $value);
        }
    }
0

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.