Allow empty cms page content - magento

When using a cms page in magento I sometimes need an empty content section. Most times this is for my homepage. But magento forces me to put something in content before it can be saved.
Is there a way to get magento to allow empty cms page content?

You can use an empty div or span

The Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Content::_prepareForm() method dispatches the adminhtml_cms_page_edit_tab_content_prepare_form event. You can observe this event, grab the field from the form object which is passed into the event, and change its required property to false.

This is a quick and dirty fix, you should really override the admin class so you won't lose the change when you next upgrade.
Anyways, in file app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php, in function _prepareForm(), line 82, change:
$contentField = $fieldset->addField('content', 'editor', array(
'name' => 'content',
'style' => 'height:36em;',
'required' => true,
'disabled' => $isElementDisabled,
'config' => $wysiwygConfig
));
to
$contentField = $fieldset->addField('content', 'editor', array(
'name' => 'content',
'style' => 'height:36em;',
'required' => false,
'disabled' => $isElementDisabled,
'config' => $wysiwygConfig
));

add <div>‍</div> inside your empty elements to stop magento cms from removing them

Its not particularly elegant, but you can just enter and/or hide the content via CSS

Related

Magento creating custom attribute with custom validations

I need to create an attribute. Also i need to validate that attribute value. So i created a new .js file and add some functions. Then in setup file, i call the function name. But after creating the attribute that validation class wont come with the field.
$installer->addAttribute(MageTest_Module_Model_Name::ENTITY, 'test_value', array(
'input' => 'text',
'type' => 'text',
'label' => 'Test Value',
'backend' => '',
'user_defined' => false,
'visible' => 1,
'required' => 0,
'position' => 60,
'class' => 'validate-testValue',
'note' => 'This should contains 2 digits. Example 00',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
'validate-testValue' is my js function name. Can anyone help me to solve this please.
Thank You.
to use Magento form validator you have to register your method with the Validator object.
Try something like that in your custom js file
Validation.add('validate-testValue','HERE your error message if the field is not valid',function(fieldValue) {
return Validation.get('IsEmpty').test(fieldValue) || fieldValue == "testValue";
});
Ok, this example will only validate if your field value is "testValue", not very usefull.
But you can adapt it I guess :)

How to get a list of cms pages in Magento?

What i'm trying todo
I have created an admin form where the user needs to select a CMS page from a drop down.
What i have tried
$form->addField('cms_page_id', 'select', array(
'label' => Mage::helper('custom/data')->__('CMS Page'),
'class' => 'required-entry',
'required' => true,
'name' => 'cms_page_id',
'values' => Mage::getSingleton('cms/page')->toOptionArray(),
'value' => $this->getCmsPageId()
));
The idea is the code gets the an option array from the CMS model. However "toOptionArray" is an invalid function for the 'cms/page' model.
My Question
How can I get an option array of CMS pages for use in an admin form in Magento?
With your code you are loading a new cms page model. To get a collection use following code and toOptionArray() will at least return something:
Mage::getModel('cms/page')->getCollection()->toOptionArray()
CMS Pages array with Links
$cms_arr = Mage::getModel('cms/page')->getCollection()->toOptionArray();
$cms_pages[""] = "-Select CMS Page-";
foreach($cms_arr as $cms){
$url = $this->getUrl($cms["value"]);
$cms_pages[$url] = $cms["label"];
}

How to add wysiwyg editor in pyrocms module

I have developed a PyroCMS custom module, but now I want to add WYSIWYG editor instead of the text area.
How can I add it?
Just append this while building the template in the controller.
->append_metadata($this->load->view('fragments/wysiwyg', $this->data, TRUE))
and then
echo form_textarea(array('id' => 'body', 'name' => 'code', 'value' => '', 'rows' => 30, 'class' => 'wysiwyg-advanced'));
Hopefully this will help you sometime..
Update:
With PyroCMS 2.2, $this->data has been deprecated.
In your controller you would need to change
->append_metadata($this->load->view('fragments/wysiwyg', $this->data, TRUE))
to
->append_metadata($this->load->view('fragments/wysiwyg', compact('items'), TRUE))

Magento admin grid sending data from Action to Controller

I'm trying to write a custom action to run off of an admin grid that I have built. Is it possible to send a value from a column in the grid to the controller via either get or post?
I've tried googling, but I cannot find a proper explanation for this anywhere. A link to an explanation of the column settings ('getter', 'type' etc.) would also be useful if this is available.
Add this code to your Grid.php:
$this->addColumn('action',
array(
'header' => Mage::helper('yourmodulename')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('yourmodulename')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
That will build an "Edit" URL with the Id of the selected row as part of the URL. It will look something like <frontname>/<controllername>/edit/id/<value> where value is returned by the getter getId().
The getter field will execute any of the standard Magento magic getters, ie any attribute is gettable. So you could have getName or getProductUrl or getIsLeftHanded if you wanted and your controller can parse the attribute.
The controller can then retrieve that passed value using Mage::app()->getRequest()->getParam('attributename');
In terms of documentation/tutorials, have a read of this article on the website of #AlanStorm as it might help.
HTH,
JD

Getting disabled checkboxes in Grid for a custom admin module in Magento

I am working on a custom module in magento admin that uses the ‘sales/order_grid_collection’ class to show the grid of all orders. The grid appears fine.
However, the first column of the grid is of ‘increment_id’, unlike the actual orders grid where the first column has checkboxes for mass action. I am getting this in spite having copy-pasted almost all the code for the _prepareColumns method from the original order module.
So I tried adding a first column of checkboxes manually inside the _prepareColumns method as follows
$this->addColumn('order_id', array(
'header_css_class' => 'a-center',
'header' => Mage::helper('sales')->__('Assigned'),
'type' => 'checkbox',
'width' => '20px',
'field_name' => 'orders[]',
'align' => 'center',
'renderer' => new Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Checkbox(),
'index' => 'order_id'
));
Upon doing this, the chekboxes do appear but they are disabled.
What am I missing here ?
Thanks
What shows up the checkboxes for mass action is the _prepareMassaction() method (see for example Mage_Adminhtml_Block_Sales_Order_Grid line 151-199 on v1.5), do you copy-pasted also in your Namespace_Module_Block_Adminhtml_Yourpath_Grid class?
If so, please paste it here to see if there is something wrong about it

Resources