Changing the height of ckeditor from a zend form - zend-framework

I am trying to set the height of a ckeditor I am using. Here is what I currently have:
$this->addElement('textarea', 'text_field', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', true, array(0, 3000)),
),
'decorators' => array('ViewHelper'),
'required' => false,
'attribs' => array('class' => 'ckeditor'),
'label' => 'Please enter text below',
'value' => isset($this->_text_data[0]['text']) ? $this->_text_data[0]['text'] : ''
));
This comes from my form, this is then called in my .phtml file by the following:
<?=$this->element->getElement('text_field')?>
I have looked everywhere and tried adding:
'height' => '100px',
and:
'config' => array(
'toolbar' => 'Full',
'width' => '550px',
'height' => '100px',
),
But neither of these have worked. The main reason I need this is I have a text area (using the ckeditor in order to allow the input information to be formatted in a particular way) which is quite long (the default height I am assuming) but it is only ever a few lines input into the box, hence the reason I want it smaller as it takes up too much space on the page.
Thanks in advance
Iain

I made a form element and a helper using ZendX_JQuery_View_Helper_UiWidget to create a CKEditor with the jQuery adapter. Here's the code of both files :
ZendExt_Form_Element_CKEditor :
class ZendExt_Form_Element_CKEditor extends ZendX_JQuery_Form_Element_UiWidget
{
/**
* Use formCKeditor view helper by default
* #var string
*/
public $helper = 'formCKEditor';
/**
* Default ckeditor options
*
* #var array
*/
public $jQueryParams = array(
'toolbar' => 'Basic'
);
}
And ZendExt_View_Helper_FormCKEditor :
class ZendExt_View_Helper_FormCKEditor extends ZendX_JQuery_View_Helper_UiWidget
{
static $set = false;
public function formCKEditor($name, $value = null, $params = null, $attribs = null)
{
$hTextA = new Zend_View_Helper_FormTextarea();
$hTextA -> setView($this -> view);
$xhtml = $hTextA -> formTextarea($name, $value, $attribs);
$xhtml .= '<script type="text/javascript">$(document).ready(function(){$("#' . $this->_normalizeId($name) . '").ckeditor(' . (!is_null($params) ? 'function(){},' . Zend_Json_Encoder::encode($params) : '') . ')});</script>';
if (self::$set == false) {
$this -> view -> headScript() -> appendFile($this -> view -> baseUrl() . '/js/ckeditor/ckeditor.js');
$this -> view -> headScript() -> appendFile($this -> view -> baseUrl() . '/js/ckeditor/adapters/jquery.js');
self::$set = true;
}
return $xhtml;
}
}
You can use it as any other ZF form element once you copied these 2 files into :
* libraries/ZendExt/Form/Element/ for ZendExt_Form_Element_CKEditor class
* libraries/ZendExt/View/Helper/ for ZendExt_View_Helper_FormCKEditor class
and added the ZendExt namespace in your configuration file (or if you already have a library of yours and want to use it, just put both files in it and change the name of the classes to reflect yours). Then, you'll have tel ZF that ZendExt/View/Helper is a directory to look in for view helpers (in a .ini config file it would look like : resources.view.helperPath.ZendExt_View_Helper = "ZendExt/View/Helper").
Then in your code, just call $ckEditor = new ZendExt_Form_Element_CKEditor(); to create a new CKEditor. You may then add all params you want to the element using $ckEditor -> setJQueryParam($key, $value); as specified in the documentation here : http://framework.zend.com/manual/fr/zendx.jquery.html . For example : $ckEditor -> setJQueryParam('height', '100px');. I understand it's not a jQuery component, but it was the easiest way to be able to make it as everything needed is available there.
To display it, in your view just do <?=$this -> ckEditor?> and you're good.
Make sure you put your ckeditor.js and adapters/jquery.js in your public directory under /js/ckeditor/ or change the path accordingly in the helper.

You'll need to specify the dimensions of the editor when you create it (i.e., in the Javascript part). CKEditor replaces the original form element with its own code, so your changes in the dimensions will be lost.
For instance, if you create it using the jQuery interface, it would be something like the following:
var config = {
width: '550px',
height: '100px'
};
// Initialize the editor.
$('.jquery_ckeditor').ckeditor(config);
Hope that helps...

Related

TYPO3 TCA make the 'default' value dynamic

The title is rather self explanatory, but what i would like to have is a dynamic default value.
The idea behind it is to get the biggest number from a column in the database and then add one to the result. This result should be saved as the default value.
Lets take for example this code:
$GLOBALS['TCA'][$modelName]['columns']['autojobnumber'] = array(
'exclude' => true,
'label' => 'LLL:EXT:path/To/The/LLL:tx_extension_domain_model_job_autojobnumber',
'config' => [
'type' => 'input',
'size' => 10,
'eval' => 'trim,int',
'readOnly' =>1,
'default' => $result,
]
);
The SQL looks like this:
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_extension_domain_model_job');
$getBiggestNumber = $queryBuilder
->select('autojobnumber')
->from('tx_extension_domain_model_job')
->groupBy('autojobnumber')
->orderBy('autojobnumber', 'DESC')
->setMaxResults(1)
->execute()
->fetchColumn(0);
$result = $getBiggestNumber + 1;
So how can i do that "clean"?
I thought about processCmdmap_preProcess but i dont know how to pass the value to the coorisponding TCA field. Plus i do not get any results on my backend when i use the DebuggerUtility like i get them when i use processDatamap_afterAllOperations after saving the Object.
Can someone point me to the right direction?
I don't think it is supported to create a dynamic default value, see default property of input field.
What you can do however, is to create your own type (use this instead of type="input"). You can use the "user" type. (It might also be possible to create your own renderType for type="input", I never did this, but created custom renderTypes for type= "select").
You can look at the code of InputTextElement, extend that or create your own from scratch.
core code: InputTextElement
documentation for user type
more examples in FormEngine documentation
Example
(slightly modified, from documentation)
ext_localconf.php:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][<current timestamp>] = [
'nodeName' => 'customInputField',
'priority' => 40,
'class' => \T3docs\Examples\Form\Element\CustomInputElement::class,
];
CustomInputElement
<?php
declare(strict_types = 1);
namespace Myvendor\MyExtension\Backend\FormEngine\Element\CustomInputElement;
use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
// extend from AbstractFormElement
// alternatively, extend from existing Type and extend it.
class CustomInputElement extends AbstractFormElement
{
public function render():array
{
$resultArray = $this->initializeResultArray();
// add some HTML
$resultArray['html'] = 'something ...';
// ... see docs + core for more info what you can set here!
return $resultArray;
}
}

Yii2 remember sort option after submit the searchForm

I use an ActiveForm in Yii2 for my SearchModel. After click on search button the form fields remember previous values but SorterDropdown is refreshed.
<?php echo SorterDropdown::widget(['sort' => $dataProvider->sort,
'label' => $model->sortedBy($dataProvider->sort->attributes),])
?>
SorterDropdown is just a wrapper of ButtonDropdown.
How can I forse the SorterDropdown to remember sort order (and show it) after the form submition?
class SorterDropdown extends LinkSorter
{
public $label;
protected function renderSortLinks()
{
$attributes = empty($this->attributes) ? array_keys($this->sort->attributes) : $this->attributes;
$links = [];
foreach ($attributes as $name) {
$links[] = Html::tag('li', $this->sort->link($name, ['tabindex' => '-1']));
}
if (empty($this->label))
$this->label = 'Sort';
return \yii\bootstrap\ButtonDropdown::widget([
'encodeLabel' => false,
'label' => $this->label,
'dropdown' => [
'items' => $links,
],
]);
}
You should add some class to li element, which indicate active state of it and special style in CSS file.

Add wysiwyg editor successfully with image insert for magento 1.5.2

How can we add wysiwyg editor in magento custom module?
1) open file Block_Adminhtml__Edit_Tab_Form
edit field
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('developerpage_form', array('legend'=>Mage::helper('developerpage')->__('Item information')));
/* add below code here */
$configSettings = Mage::getSingleton('cms/wysiwyg_config')->getConfig();
$configSettings['files_browser_window_url'] = $this->getBaseUrl().'admin/cms_wysiwyg_images/index/';
Mage::getSingleton('cms/wysiwyg_config')->setConfig($configSettings);
/* for fieldset add like below */
$fieldset->addField('detail', 'editor', array(
'name' => 'detail',
'label' => Mage::helper('developerpage')->__('Content'),
'title' => Mage::helper('developerpage')->__('Content'),
'style' => 'width:700px; height:500px;',
'config' => $configSettings,
'required' => true,
));
2) open controllers/adminhtml/testcustomercontroller.php find editAction
in editAction find $this->loadLayout();
and paste the below code;
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
3) open desing/adminhtml/default/default/yourmodule xml file and add below xml
/* this is my module change with yours */
<developerpage_adminhtml_developerpage_edit>
<update handle="editor" />
</developerpage_adminhtml_developerpage_edit>
NOTE: Dont give field name or id name "content" of editor field nor in Database
Call editor content like below other wise directive would't convert
$_cmsHelper = Mage::helper('cms');
$_process = $_cmsHelper->getBlockTemplateProcessor();
echo $_process->filter(Here your database content);
Now image can be insert. :)

Form with managed files weird behaviour on form error

I have created a content type with an associated image field.
Each user is able to see a list of all the nodes of this content type and should be able to upload a new image in the appropriate field.
I've tried many solutions, but in the end I'm trying with a form and managed files.
In the page with the list of all the nodes I'm creating a lightbox with a form for each node.
Each form is created like this:
function coverupload_form($form, &$form_state, $uid, $relid) {
$form['#attributes']['id'] = 'coverup-'.$relid;
$form_state['storage']['rid'] = $relid;
$cliente = cataloghi_user_edit_get_cliente($uid);
$release = node_load($relid);
$form['cover'] = array(
'#title' => 'Carica la cover per la release '.$release->title,
'#description' => 'I file caricati devono avere estensione \'.jpeg\', risoluzione di 1440x1440 e dimensione massima di 5MB',
'#type' => 'managed_file',
'#upload_location' => 'public://clienti/'.$cliente->title.'/cover',
'#upload_validators' => array(
'file_validate_extensions' => array('jpeg, jpg'),
// Pass the maximum file size in bytes
'file_validate_size' => array(5*1024*1024),
'file_validate_image_resolution' =>array('1440x1440', '1440x1440'),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('CARICA'),
);
return $form;
}
function coverupload_form_submit($form, &$form_state) {
$file = file_load($form_state['values']['cover']);
// Change status to permanent.
$file->status = FILE_STATUS_PERMANENT;
// Save.
file_save($file);
$nodo = node_load($form_state['storage']['rid']);
$nodo->field_release_copertina['und'][0] = (array)$file;
if($nodo = node_submit($nodo)) { // Prepare node for saving
node_save($nodo);
}
}
All the forms have display: none, and when the user click on the cover upload button only the corresponding form is showed in the lightbox.
Well, everything works fine when the image is validated.
The problems start when the image is not validated (like if it's below 1440x1440px).
If I check the lightbox with the inspector, the correct number of forms is generated but they all refer to the same node (so they all have id 'coverup-17' for example).
I have checked everything, and it seems like I pass the correct values to the form everytime, so I'm starting to think that it may be a problem connected with my poor understanding of forms.
Would it be better to try a different type of approach?
Thanks and sorry for if this is a bit messy...
I managed to solve the problem.
It depended on the fact that I had multiple instances of the same form on the same page.
I implemented hook_forms().
function mymodule_forms($form_id, $args) {
$forms = array();
if(strpos($form_id, 'coverupload_form_') === 0) {
$forms[$form_id] = array(
'callback' => 'coverupload_form',
'callback arguments' => array($args[0], $args[1]),
);
}
return $forms;
}
and then I changed my form call to
drupal_render(drupal_get_form('coverupload_form_'.$relid, $arg1, $arg2));

Write hyperlink inside the Zend Form?

I am using Zend-Framework in my project. I made a login form using the Zend Form that contains the User Id and Passwords fields with a submit button. Everything is working fine in the login form.
How do I add two hyperlinks inside the login form that is one for the Sign-Up and other for the Forget Password?
I've faced the same problem before, and solved it by creating a custom Zend_Form_Element_Html, as follows:
class Zend_Form_Element_Html extends Zend_Form_Element_Xhtml {
/**
* Default form view helper to use for rendering
* #var string
*/
public $helper = 'formNote';
public function isValid($value, $context = null) {
return true;
}
}
So, in your form you just have to do the following:
$tag = new Zend_Form_Element_Html('forgetPassword');
$tag->setValue('Forgotten your password?');
$this->addElement($tag);
Hope this helps!
In your viewscript file where you print the form, e.g. login.phtml
echo $this->form;
you can specify any other html markup, e.g. links
echo "<p><a href='".$this->url ( array ('controller' => 'authentication',
'action' => 'lostPW' ) )."'>
Lost pw </a></p>";
So you actually do not write it in the form itself but in the view script where you echo the form.
Try this:
$passwordElement->setDescription('Forgot password?');
$passwordElement->getDecorator('Description')->setOption('escape', false);
Description decorator will add this text beside your field.
You can use Zend_Form_Decorator_ViewScript
Or, create a custom Zend_Form_Element to render HTML elements or ViewScript.
For only decorators use directly in the form try:
$this->addElement(new Zend_Form_Element_Note(array(
'name' => 'forgotten',
'value' => __('Forgot your password?'),
'decorators' => array(
array('ViewHelper'),
array('HtmlTag', array(
'tag' => 'a',
'href' => $this->getView()->url(array(
'remind'
))
)),
)
)), 'forgotten');