Extending Magento CMS: Uploading PDF Files via Wysiwyg Editor
In this technical guide, we’ll explore how to extend the built-in content management system (CMS) of Magento to allow uploading PDF files using the WYSIWYG editor in version 1.9.1.0. We’ll cover step-by-step instructions and provide a working example.
Step 1: Create the Configuration File
First, let’s create our new module configuration file at app/etc/modules/Pdf_WysiwygFiles.xml:
<?xml version="1.0"?>
<config>
<modules>
<Pdf_WysiwygFiles>
<active>true</active>
<codePool>local</codePool>
</Pdf_WysiwygFiles>
</modules>
</config>
This file tells Magento that our new module is active and part of the local code pool.
Step 2: Define Allowed File Types
Next, we need to define which file types are allowed in our WYSIWYG editor. Create a config.xml file at app/code/local/Pdf/WysiwygFiles/etc/config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Pdf_WysiwygFiles>
<version>1.0.0</version>
</Pdf_WysiwygFiles>
</modules>
<adminhtml>
<cms>
<browser>
<extensions>
<allowed>
<jpg>1</jpg>
<jpeg>1</jpeg>
<png>1</png>
<gif>1</gif>
<pdf>1</pdf>
</allowed>
</extensions>
</browser>
</cms>
</adminhtml>
</config>
Here, we’ve added <pdf>1</pdf> to the allowed extensions list. This allows PDF files to be uploaded via the WYSIWYG editor.
Step 3: Verifying the Setup
After following these steps and clearing your Magento cache (rm -rf var/cache/* in the root directory), you should now see that the WYSIWYG editor in the CMS pages allows uploading PDF files.
To confirm this works:
- Navigate to
CMS > Pages. - Click on a page name (or create a new one).
- In the content field, click the “Insert Image” button.
- Select the “Upload” tab at the top of the modal window.
- Try uploading a PDF file.
The upload should now succeed without displaying any errors or preventing you from saving the page.
Adding a Custom Preview Icon for Uploaded PDFs
To add a custom preview icon for each uploaded PDF, we’ll need to extend Magento’s core functionality. This involves creating an observer and modifying the JavaScript used in the WYSIWYG editor.
This process is quite complex and requires deep knowledge of Magento’s event system and its integration with TinyMCE (the WYSIWYG editor library). It goes beyond the scope of this basic guide, but it can be achieved by following a detailed tutorial or consulting an experienced Magento developer.
Conclusion
In this post, we successfully extended the CMS functionality in Magento 1.9.1.0 to allow uploading PDF files via the WYSIWYG editor. This demonstrates how you can modify Magento’s core behavior using configuration files and simple XML changes.
Remember that modifying core files is generally discouraged, as it may cause issues during upgrades. If you’d like a more robust solution or need assistance with adding custom icons for uploaded PDFs, feel free to contact Laravel Company for professional development services.