Magento Custom Module - WYSIWYG image browse issue - wysiwyg

I have a custom module with a content field (WYSIWYG editor)
When I select the insert image button, the following popup appears. For some reason the 'browse' button at the side of the Image URL has disappeared. Can someone point me in the right direction to get the image icon back? (what block/controller etc)
What is required when adding the full featured WYSIWYG editor to a custom magento module?
This is my form field element within Form.php (block)
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
));
Thank you.
Jonny

Had to find out the hard way, but the solution is quite simple:
Please check the permissions of your Role your Admin is in unser System=>Permissions=>Roles
There you can find in the Tab "Role Resources" the Checkbox "Media Gallery". Make sure this checkbox is ticked!
Then, clean cache, log out and in again and it should work.
Cheers!

I managed to sort this by adding some configuration options to the field,
Add the following code above the addField() of your WYSIWYG,
$configSettings = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array( 'add_widgets' => false, 'add_variables' => false, 'add_images' => false, 'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/'));
Once you've added the code, you need to add another param to the addField called 'config' calling your $configSettings variable.
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
'config' => $configSettings
));

Related

Disable field in the crud

I need to update a record, but I want to display some fields as disabled for editing. I don't want to let the user edit a certain field, but I want to display them
If I understand your problem correctly then you may want to try something like this.
CRUD::addField([
'name' => 'nameOfYourField',
'label' => 'nameOFLabel',
'type' => 'number',
'attributes' => [
'readonly' => 'readonly',
],
]);
You can also use 'disabled' => 'disabled', but it depends what you want exatly to achieve with the values.
Check it out here

How to add custom action button in suiteCRM module sub panel list?

I need some suggestion in my suite CRM module integration.
I have a sub-panel in one of my modules and required to add one more edit button to redirect to a custom form to take some input from the user for each row separately.
Below is a sample image of my sub-panel list view.
In the above image on click of the edit button of a row, there is a remove button, I want to add one more custom button after remove and need to redirect from there to my new form.
I have checked some of forums and blogs but didn't found the solution.
To add a button you will need to modify the metadata of that sub-panel. In metadata, you will see the following code for the Edit and Remove buttons:
'edit_button' =>
array (
'vname' => 'LBL_EDIT_BUTTON',
'widget_class' => 'SubPanelEditButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'remove_button' =>
array (
'vname' => 'LBL_REMOVE',
'widget_class' => 'SubPanelRemoveButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
You can add your new button using same array syntax. As you can see that every button use specific widget class(defined as widget_class) therefore you will need to add new widget_class class for that. You can find existing widget classes in this folder: include/generic/SugarWidgets.
Cheers!

How do I allow html tags in label for Zend form element using addElement()?

I am brand new to Zend and I've been given a project to make adjustments on. I'd like to add html to the labels for my form elements but I can't seem to get it right.
Here's what I have:
$this->addElement('text', 'school_name', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 150)),
),
'required' => true,
'label' => 'Name* :<img src="picture.png">,
'size' => '90',
));
As is, of course, the <img src="picture.png"> text gets escaped and the whole string is displayed.
I've read that I need to use 'escape' => false in some capacity but I can't figure out where/how to use it in my specific case.
Any help would be great. Thanks!
After calling addElement fetch the label's decorator and change the escape setting:
$form->getElement('school_name')->getDecorator('label')->setOption('escape', false);
If you use this type of label a lot, you should consider writing a custom decorator.
You can also use the disable_html_escape in 'label_options' when adding an element to the form:
$this->add(array(
....
'options' => array(
'label' => '<span class="required">Name</span>,
'label_options' => array(
'disable_html_escape' => true,
)
),
...
));
Credit to Théo Bouveret's post 'Button content in ZF2 forms' for the answer.

$this->request->data EMPTY - When I have disabled Fields CakePHP 2

I have a form which has some disabled fields, when the form is submitted both $this->request->data and $_POST is empty, removing the disabled fields and it is fine again. I would have though it would still pass though the non-disabled fields. I've even tried to remove the disabled field attribute when the submit button is pushed but this still returns an empty array.
Is there something cake related that might be causing this?
Thanks
// SNIPPET FROM THE VIEW CODE:
$this->Form->create('Card', array('class' => 'GeneralValidate'));
$this->Form->input('Card.property_id', array('type'=>'select', 'empty'=>true , 'class' => 'required adminOnlyField', 'div' => array('class' => 'required')));
$this->Form->input('Card.building_id', array('type'=>'select', 'empty'=>true, 'id' => 'BuildingSelector', 'class' => 'adminOnlyField', 'label' => 'Building (If Applicable)'));
$this->Form->input('Prospect.waiting_list_details', array('value' => $prospect['Prospect']['waiting_list_details']));
$this->Form->input('SaleDetail.property_sold', array('class' => 'checkbox', 'checked' => $ps_checked));
$this->Form->input('SaleDetail.date_conditions_met', array('type'=>'text', 'class' => 'text date_picker adminOnlyField', 'value' => $this->Date->format($saledetail['SaleDetail']['date_conditions_met'])));
$this->Form->button('Save & Continue', array('type'=>'submit', 'label' => 'Save', 'name' => 'quicksave' , 'class' => 'submit long clear_ready_only'));
// JS FROM THE VIEW
$(function () {
var $adminOnly = $('.adminOnlyField');
$adminOnly.prop('disabled',true).prop('readonly',true);
$adminOnly.attr("onclick","return false");
$adminOnly.attr("onkeydown","return false");
$adminOnly.removeClass('required');
$adminOnly.removeClass('date_picker');
$('.clear_ready_only').click(function(e)
{
e.preventDefault();
$adminOnly.prop('disabled',false).prop('readonly',false);
$adminOnly.attr("onclick","return true");
$adminOnly.attr("onkeydown","return true");
$('#CardModifysaleForm').submit();
});
});
That's the way HTML works, disabled don't get posted. CakePHP can't change what is sent from the browser. If you still want the value you can set it as a hidden element.
Update
Some problems I see:
Missing Form::end() in view (always a good idea to insert it).
You never said your form was submitted from JS, first test with a simple form POST then JS.
Your JS code is set to submit a form by ID CardModifysaleForm. There's no such ID in your supplied view code and you're not setting your form to that ID from the snippet you supply.
I ended up removing the disabled option from this, leaving the ready only and added some addition CSS stylings so it looked disabled to the user. This is not the exact answer to the question but works as a different approach.

magento custom module which uploads multiple images

I want to create custom module which can upload multiple images like product.I have created one custom module but it uploads only one image.
form.php
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('footertop')->__('File'),
'name' => 'filename',
));
I think you need to create your custom renderer for the image field. For this create this class in your module:
class [YOURNamespace]_[YOURModule]_Block_Adminhtml_[YOUREntity]_Helper_Image extends Varien_Data_Form_Element_Image{
//make your renderer allow "multiple" attribute
public function getHtmlAttributes(){
return array_merge(parent::getHtmlAttributes(), array('multiple'));
}
}
Now at the top of your _prepareForm (where you add your fields) add this line before adding any field:
$fieldset->addType('image', '[YOURNamespace]_[YOURModule]_Block_Adminhtml_[YOUREntity]_Helper_Image');
Or if you want to be "politically correct" add it this way:
$fieldset->addType('image', Mage::getConfig()->getBlockClassName('[YOURmodule]/adminhtml_[YOURentity]_helper_image'));
This will tell Magento that in your current fieldset, all the fields with type image should be rendered by your own class.
Now you can add your field like similar to how you did it:
$fieldset->addField('image', 'image', array(
'name' => 'image[]', //declare this as array. Otherwise only one image will be uploaded
'multiple' => 'multiple', //declare input as 'multiple'
'label' => Mage::helper('YOURmodule')->__('Select Image'),
'title' => Mage::helper('YOURmodule')->__('Can select multiple images'),
'required' => true,
'disabled' => $isElementDisabled
));
That's it.
Don't forget to replace the placeholders ([YOURModule] and others) with your values.