hook_textarea is broken, legacy.inc code had: http://drupaldocs.org/api/head/function/form_textarea ... it invokes modules that use the hook_textarea such as TinyMCE or HTMLArea.

This patch adds that back in.

However, after talking with webchick on IRC maybe this hook is no longer needed because of #pre and #post? Docs aren't clear if this is the case, please advise and/or apply patch, thanks!

CommentFileSizeAuthor
form.inc_2.patch1.68 KBm3avrck

Comments

walkah’s picture

+1 for including this, as it makes one less thing the contrib authors would have to update. :P

webchick’s picture

I should clarify, not #pre and #post, but #prefix and #suffix, which would allow appending of markup before and after a form element. These are documented here:

http://drupaldocs.org/api/head/file/contributions/docs/developer/topics/...
http://drupaldocs.org/api/head/file/contributions/docs/developer/topics/...

However, I'm not 100% clear on what hook_textarea actually does so I may be mistaken. :)

Thox’s picture

The currently forms API alternative would be to use hook_form_alter and change all append the pre and post code to all textareas. Simply bringing back hook_textarea seems a lot easier.

The main purpose is for WYSIWYG controls, but I also use it for adding a spellcheck to all textareas (although I've worked around that).

m3avrck’s picture

Yes I agree, right now it seems in alter_form() you have to loop through all form elements to find the textareas, and then set #suffix (or #prefix) as necessary. Seem that my above patch would really simplify this.

Thoughts on best route to take?

m3avrck’s picture

Without this patch, each hook_textarea would have to be renamed and use the following code:

/**
 * Implementation of modulename_form_alter().
 */
function tinymce_form_alter($form_id, &$form) {

  $textareas = array();
  foreach ($form AS $element) {
    if ($element['#type'] == 'textarea') {
      $textareas[] = $element;
    }
  }

// add your hook_textarea specific stuff here then for each $textarea found

So either the patch above or every hook_textarea() turns into above, that seems to be all I can dig up :)

m3avrck’s picture

Just to further comment, if we used the proposed patch, it is only a one line changed to upgrade TinyMCE so it works.

If we don't, upgrading TinyMCE will require the above code, plus some other tweaks here and there.

My vote would be to add the patch so that the hook still works. form_alter() is very powerful and useful, but in the case of hook_textarea (which was meant specifically for WYSIWYGs) it seems best to leave that.

dries’s picture

I'd rather not introduce hooks for the sake of introducing hooks. It's better to have one way of doing things, rather than 3 ways of doing things. The form API has a generic mechanism to alter forms; let's use that rather than re-introducing special case code.

m3avrck’s picture

Status: Needs review » Closed (fixed)

Dries I see your point and I guess we'll all just have to do a little more work to update our modules then :-p

Wesley Tanaka’s picture

Just to further comment, if we used the proposed patch, it is only a one line changed to upgrade TinyMCE so it works.

I'm about to install this patch on my site for now until the TinyMCE in CVS is updated for the new API. What's the one line change to TinyMCE, or has it already been checked into CVS?

m3avrck’s picture

TinyMCE has been updated and is waiting for this patch to be committed: http://drupal.org/node/38038 ... after that TinyMCE will work and I'll be going through cleaning up any remaining bugs.

scroogie’s picture

I thought with your proposed changes in #5 the patch would not be needed?

Wesley Tanaka’s picture

I think something analagous to the changes in #5 just got committed: http://drupal.org/cvs?commit=21743

scroogie’s picture

I dont think so, there is no _form_alter() function defined in the applied patch.

m3avrck’s picture

Oh no, the patch changed again :-) The new patch uses hook_elements() instead, it is the preferred way and there is one last pending patch that fixes this approach when dealing with #prefix and #suffix when using #process. Sorry for the confusion!