Skip to main content
wysiwyg editor

Alter WYSIWYG's form height

Once the installation of a Drupal instance is done, I guess almost 90% of the developers would first download "What You See Is What You Get".  Inline formatting, Text format options, Hyperlinks, Media and iframe support all these makes WYSIWYG a heaven to opt first after installation. No developer would have the heart to say any shortcoming in this feature rich but yet simple module, I am no exception to this too !

But in one of my present projects I had a requirement to change the height of the field which had WYSISYG. For example the body field is what in most cases will have the WYSISYG and I was supposed to make this field of fixed height. At first glance this was a clean CSS work for me. Latter on using Inspect Element in chrome I woke myself up from that dream to see the reality.

The body field had a iframe, which indirectly implies my helpless situation ! It was not impossible to do this with CSS, but I wanted a better and perfect solution to make the fix. I went through some API related to WYSISYG and came with the best fix. 

  1. /**
  2. * Implements hook_wysiwyg_editor_settings_alter()
  3. **/
  4. function hook_wysiwyg_editor_settings_alter(&$settings, $context) {
  5.   if ($context['profile']->editor == 'ckeditor' && isset($settings['height'])) {
  6.     $settings['height'] = 150;
  7.   }
  8. }

The hook_wysiwyg_editor_settings_alter is what does the trick here, replace the hook with your module's name (this must be placed in any of your custom module).  I made use of ckeditor as library for WYSIWYG module, so make the check equivalent to your library.  Once the check passes the height of the WYSIWYG field will be resized to 150px.

This blog can be done with CSS too, but to follow the Drupal way of doing I strongly insist developers to follow this method.

Comments

fsdffs (not verified)

Tue, 11/25/2014 - 17:34

It would be useful, but what should I do with that function to work? It is not clear for me? Should I create a custom module with your text inside?

HI,

You can place it in a module and replace the hook with your module name. If not, you can place it in your theme's template.php and replace the hook with your theme's name.

But I would prefer option 1 as it gives more ease to disable and unable this features.