0

I'm trying to rewrite Magento wysiwyg config class, specifically one constant,, all in the need to change the default upload location of images in admin (for products, cms pages etc..) and this is my code:

etc/modules/Mk_ImagePath.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Mk_ImagePath>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Mk_ImagePath>
  </modules>
</config>

in my app/code/local/Mk/ImagePath/etc

<?xml version="1.0"?>
<config>
  <modules>
    <Mk_ImagePath>
      <version>0.1.0</version>
    </Mk_ImagePath>
  </modules>
  <global>
    <helpers>
      <imagepath>
        <class>Mk_ImagePath_Helper</class>
      </imagepath>
    </helpers>
    <models>
      <imagepath>
        <class>Mk_ImagePath_Model</class>
        <resourceModel>imagepath_mysql4</resourceModel>
      </imagepath>
            <cms>
                <rewrite>
                    <wysiwyg_config>Mk_ImagePath_Model_Cms_Wysiwyg_Config</wysiwyg_config>
                </rewrite>
            </cms>
    </models>
  </global>
</config> 

and in my app/code/local/Mk/ImagePath/Model/Cms/Wysiwyg

<?php
class Mk_ImagePath_Model_Cms_Wysiwyg_Config extends Mage_Cms_Model_Wysiwyg_Config
{
    const IMAGE_DIRECTORY = 'wysiwyg' . 'test';
}

I don't have any errors in console but I have a filling that my module is not fired at all? I'm on magento 1.7.0.2 if that helps,, thanks!

0

The first error is in here:

const IMAGE_DIRECTORY = 'wysiwyg' . 'test';

You cannot declare constants using concatenation. Declare it like this:

const IMAGE_DIRECTORY = 'wysiwygtest';

But this won't do you any good, because the image path is determined by Mage_Cms_Helper_Wysiwyg_Images::getStorageRoot() that looks like this:

public function getStorageRoot()
{
    return Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
        . DS;
} 

This means that even if you override the Mage_Cms_Model_Wysiwyg_Config class the method above still uses the constant from the original class.
You should also override the method I mentioned to make use of your class constant: in config.xml add this on the same level as <models> (sibling).

<helpers>
    <cms>
        <rewrite>
            <wysiwyg_images>Mk_ImagePath_Helper_Cms_Wysiwyg_Images</wysiwyg_images>
        </rewrite>
    </cms>
</helpers>

Then create the file app/code/local/Mk/ImagePath/Helper/Cms/Wysiwyg/Images.php with the following content:

<?php
class Mk_ImagePath_Helper_Cms_Wysiwyg_Images extends Mage_Cms_Helper_Wysiwyg_Images{
    public function getStorageRoot()
    {
        return Mage::getConfig()->getOptions()->getMediaDir() . DS . Mk_ImagePath_Model_Cms_Wysiwyg_Config::IMAGE_DIRECTORY
            . DS;
    } 
}
  • Thank you very much Marius!!! I did what you suggested and I think that this helper addition to confing.xml did the trick! – Kresimir Pendic Jul 25 '13 at 12:12

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.