0
votes

I recently modified a Magento video extension so that one of the fields used the WYSIWYG editor, instead of just being plain text, but now nothing entered saves.

The field was originally called 'content' so I had to change that to 'description' so that everything displayed properly, and made sure I changed 'content' to 'description' everywhere I thought I'd need to (where the property is called in the design/..../template/ folder, where the property is created in the form).

The WYSIWYG editor now displays correctly, but it has wiped all the original descriptions, and won't let me save any more (if I type a new description and press 'save', when I go back to the settings for the video, the description is not there.

I don't think any of the remaining instances of the word 'content' in the extension are related to the property, as they appear in pairs (e.g. two files, one videocontroller.php, one videocategorycontroller.php, both used in the same way, but the 'video category' pages never used 'content' in the same way as the video pages).

The only other file I thought could have sorted it was the SQL installation file which contained:

<?php
$installer = $this;
$installer->startSetup();
$installer->run("
-- DROP TABLE IF EXISTS {$this->getTable('video')};
CREATE TABLE {$this->getTable('video')} (
`video_id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`filename` varchar(255) NOT NULL default '',
`video_category_ids` varchar(255) NOT NULL default '',
`description` text NOT NULL default '',
`status` smallint(6) NOT NULL default '0',
`created_time` datetime NULL,
`update_time` datetime NULL,
PRIMARY KEY (`video_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");

$installer->endSetup();

where 'description' has already been changed from 'content', but changing this and uploading it made no difference. There is an sql upgrade file, do I need to make a new sql upgrade file?

Apart from that I'm stumped, any thoughts?

Edit: Saveaction as requested

public function saveAction() {
    if ($data = $this->getRequest()->getPost()) {
        if (isset($data['video_category_ids']))
            $data['video_category_ids'] = implode(',', $data['video_category_ids']);

        $data['filename'] = Mage::helper('videoblog')->trimYouTubeUrlFormat($data['filename']);

        $model = Mage::getModel('video/video');
        $model->setData($data)
                ->setId($this->getRequest()->getParam('id'));

        try {
            if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                $model->setCreatedTime(now())
                        ->setUpdateTime(now());
            } else {
                $model->setUpdateTime(now());
            }

            $model->save();
            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('videoblog')->__('Video was successfully saved'));
            Mage::getSingleton('adminhtml/session')->setFormData(false);

            if ($this->getRequest()->getParam('back')) {
                $this->_redirect('*/*/edit', array('id' => $model->getId()));
                return;
            }
            $this->_redirect('*/*/');
            return;
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            Mage::getSingleton('adminhtml/session')->setFormData($data);
            $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            return;
        }
    }
    Mage::getSingleton('adminhtml/session')->addError(Mage::helper('videoblog')->__('Unable to find video to save'));
    $this->_redirect('*/*/');
}

edit: code\community\Aurora\Videoblog\Block\Adminhtml\Video\Edit\form.php:

class Aurora_Videoblog_Block_Adminhtml_Video_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {

protected function _prepareForm() {
    $form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
        'method' => 'post',
        'enctype' => 'multipart/form-data'
            )
    );

    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

protected function _prepareLayout() {
    parent::_prepareLayout();
    if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
        $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
    }
    }
}

code\community\Aurora\Videoblog\Block\Adminhtml\Video\Edit\Tabs\form.php:

class Aurora_Videoblog_Block_Adminhtml_Video_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {

protected function _prepareForm() {
    $form = new Varien_Data_Form();
    $this->setForm($form);
    $fieldset = $form->addFieldset('video_form', array('legend' => Mage::helper('videoblog')->__('Video')));

    $fieldset->addField('title', 'text', array(
        'label' => Mage::helper('videoblog')->__('Title'),
        'class' => 'required-entry',
        'required' => true,
        'name' => 'title',
    ));

    $fieldset->addField('filename', 'text', array(
        'label' => Mage::helper('videoblog')->__('Video'),
        'class' => 'required-entry',
        'required' => true,
        'name' => 'filename',
        'after_element_html' => '<small style="color: red;display: block">'.Mage::helper('videoblog')->__("Youtube video id after 'v=' (e.g. ear2SunyaZE)").'</small>',
    ));

    $fieldset->addField('video_category_ids', 'multiselect', array(
        'label' => Mage::helper('videoblog')->__('Category'),
        'name' => 'video_category_ids',
        'required' => true,
        'value' => '1',
        'values' => Mage::helper('videoblog')->getCategory(),
    ));

    $fieldset->addField('status', 'select', array(
        'label' => Mage::helper('videoblog')->__('Status'),
        'name' => 'status',
        'values' => array(
            array(
                'value' => 1,
                'label' => Mage::helper('videoblog')->__('Enabled'),
            ),
            array(
                'value' => 2,
                'label' => Mage::helper('videoblog')->__('Disabled'),
            ),
        ),
    ));

    $fieldset->addField('description', 'editor', array(
        'name' => 'description',
        'label' => Mage::helper('videoblog')->__('Description'),
        'title' => Mage::helper('videoblog')->__('Description'),
        'style' => 'width:500px; height:200px;',
        'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
        'wysiwyg' => true,
        'required' => true,
    ));

    if (Mage::getSingleton('adminhtml/session')->getVideoData()) {
        $form->setValues(Mage::getSingleton('adminhtml/session')->getVideoData());
        Mage::getSingleton('adminhtml/session')->setVideoData(null);
    } elseif (Mage::registry('video_data')) {
        $form->setValues(Mage::registry('video_data')->getData());
    }
    return parent::_prepareForm();
}

}
1
Can you add the code for the saveAction in `Company/Module/controllers/Adminhtml/nameController.phpRenon Stewart
Added to original posteddhall
Did you clear cache after you change the db field name (regardless if magento cache is disabled)? magento.stackexchange.com/questions/749/…Renon Stewart
yep, flushed the cache, still not saving after adding the new fieldeddhall
In saveAction do Mage::log(data); or print_r(data); is the field there?Renon Stewart

1 Answers

0
votes

you only need to change the 'label' of content field in form.php file

so you description field look like

$fieldset->addField('content', 'editor', array(
    'name' => 'content',
    'label' => Mage::helper('videoblog')->__('Description'),
    'title' => Mage::helper('videoblog')->__('Description'),
    'style' => 'width:500px; height:200px;',
    'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
    'wysiwyg' => true,
    'required' => true,
));

even though if you dont want to used the field of content then you can create new field in database using below script.

create script mysql4-upgrade-0.1.0-0.1.1.php //if your module version 0.1.0 (to 0.1.1 update version in script file)

<?php

$installer = $this;

$installer->startSetup();

$installer->run("
 ALTER TABLE {$this->getTable('video')} ADD   description varchar(255) NULL ;

");

$installer->endSetup();

open your etc/config.xml and change the version to 0.1.1 save file.

hope this help