I am trying to understand why this code in production is not working (it comes from a custom theme):
protected function _prepareLayout() {
$uploaderBlock = $this->getLayout()->createBlock('adminhtml/media_uploader');
if($uploaderBlock != null)
{
Mage::log("this is printed");
}
$this->setChild('uploader',
$uploaderBlock
);
//THE PROBLEM SHOULD BE HERE
$config = $this->getUploader()->getConfig();
if($config != null){
Mage::log("this is not printed");
$config->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/image'))
->setFileField('image')
->setFilters(array(
'images' => array(
'label' => Mage::helper('adminhtml')->__('Images (.gif, .jpg, .png)'),
'files' => array('*.gif', '*.jpg','*.jpeg', '*.png')
)
));
}
$this->setChild(
'delete_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->addData(array(
'id' => '{{id}}-delete',
'class' => 'delete',
'type' => 'button',
'label' => Mage::helper('adminhtml')->__('Remove'),
'onclick' => $this->getJsObjectName() . '.removeFile(\'{{fileId}}\')'
))
);
return parent::_prepareLayout();
}
It seems that getConfig()
called on the block returns null, can somebody point me out how to look for something wrong?
UPDATE
The code posted is about a magento extension called Mtslideshow. I am using Magento 1.8.1.0 with the latest patches applied.
I modified Image.php file:
protected function _prepareLayout() {
$this->setChild('uploader',
$this->getLayout()->createBlock('adminhtml/media_uploader')
);
$url = Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/image');
if (class_exists("Mage_Uploader_Block_Abstract")) {
// PATCH SUPEE-8788 or Magento 1.9.3
$this->getUploader()->getUploaderConfig()
->setFileParameterName('image')
->setTarget($url);
$browseConfig = $this->getUploader()->getButtonConfig();
$browseConfig
->setAttributes(
array("accept" => $browseConfig->getMimeTypesByExtensions('gif, png, jpeg, jpg'))
);
} else {
$this->getUploader()->getConfig()
->setUrl($url)
->setFileField('image')
->setFilters(array(
'images' => array(
'label' => Mage::helper('adminhtml')->__('Images (.gif, .jpg, .png)'),
'files' => array('*.gif', '*.jpg','*.jpeg', '*.png')
)
));
}
$this->setChild(
'delete_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->addData(array(
'id' => '{{id}}-delete',
'class' => 'delete',
'type' => 'button',
'label' => Mage::helper('adminhtml')->__('Remove'),
'onclick' => $this->getJsObjectName() . '.removeFile(\'{{fileId}}\')'
))
);
return parent::_prepareLayout();
}
The the image.phtml file:
<script type="text/javascript">
//<![CDATA[
<?php if (class_exists("Mage_Uploader_Block_Abstract")): ?>
var <?php echo $_block->getJsObjectName(); ?> = new SlideShow.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
<?php else: ?>
var <?php echo $_block->getJsObjectName(); ?> = new SlideShow.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getUploader()->getJsObjectName() ?>, <?php echo $_block->getImageTypesJson() ?>);
<?php endif; ?>
//]]>
And the mtslideshow.xml file:
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addJs"><file>lib/uploader/flow.min.js</file></action>
<action method="addJs"><file>lib/uploader/fusty-flow.js</file></action>
<action method="addJs"><file>lib/uploader/fusty-flow-factory.js</file></action>
<action method="addJs"><file>mage/adminhtml/uploader/instance.js</file></action>
<action method="addJs"><script>magenthemes/mtslideshow/slideshow.gallery.js</script></action>
</reference>
</default>
<mtslideshow_adminhtml_mtslideshow_index>
<reference name="content">
<block type="mtslideshow/adminhtml_mtslideshow" name="mtslideshow" />
</reference>
</mtslideshow_adminhtml_mtslideshow_index>
It kinda worked, however even if the image gets uploaded to the server, it seems that in the db the slide is not present (I imagine there is a problem when the uploader calls back the controller with the image data).
Can anybody suggest me where to look for the portion of code called by the uploader after the image upload?