Is there a way to disable tinymce on webforms. I have a client that has both and it's just too much for them to turn it off when edditing webforms.

I have tinymce set to only be visible on node/*/edit, but of course this includes webforms.

Comments

garym’s picture

Does anyone know how to exclude TinyMCE in Webforms? Syawillim, did you figure it out?
TinyMCE's inclusion and exclusion is on a per page. For example:

node/*
user/*
comment/*

is the default inclusion. My webforms are included in the node so I have these clumsy tinymce instances in 8 different textareas on each survey. Not good.

Any help is appreciated.
Thank you,

Gary

garym’s picture

I tried using PHP to control the visibility of TinyMCE in webforms but to no avail. I used the below code in the "Show if the following PHP code returns TRUE":

<?php
if ($type == "webform") {
return FALSE;
} else {
return TRUE;
}
?>

If I force a FALSE then it never shows anywhere and forcing TRUE it does shows, so the PHP code is being evaluated. But it seems maybe $type is not available at that point? I added print "nodeType:[".$type."]"; to the end of node.tpl.php to confirm "webform" is the correct string representing webforms, and it is...

Ideas?

jillelaine’s picture

i have a similar situation. i want the tinymce editor to appear on only certain 'content types'. i found this code snippet here: http://drupal.org/node/64135

i put the code snippet below into admin > settings > tinymce > (profile) edit > visibility > clicked radio button "Show if the following PHP code returns TRUE", then pasted in the code.

this code works great for EXISTING content (when i edit it), but the tinymce editor does not appear when i try to create a NEW blog, book, or page. i think this is because there is no "nid" for a NEW entry: the nid is created only AFTER the new entry is created? (nid isNull?)

does anyone have any idea how to have tinymce appear for only certain 'content types', whether they are NEW or EXISTING? your help is much appreciated! thank you! jill elaine

<?php
$match = FALSE;
$types = array('blog' => 1, 'book' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
   $match = TRUE;
}
}
return $match;
?>
jillelaine’s picture

okay, here is some code that will show tinymce on both NEW and EXISTING 'content types'...and ONLY on those 'content types'. it's a bit of a kludge...i am sure it could be more efficiently coded...but it does work. replace your desired 'content types' as needed: be sure to replace the 'content type' in both the EXISTING and NEW sections.

again, this code goes into admin > settings > tinymce > (profile) edit > visibility > clicked radio button "Show if the following PHP code returns TRUE", then pasted in the code.

thanks to vincent for code that 'makes visible' according to path: http://drupal.org/node/64135#comment-126119

<?php
$match = FALSE;

/* this section controls visibility on EXISTING content */

$types = array('blog' => 1, 'book' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
  $match = TRUE;
}
}

/* this section controls visibility on NEW content */

if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/blog")
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/book")
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/page")
{ $match = TRUE;}

return $match;
?>
syquest’s picture

I need this functionality so that a user group gets Tiny MCE options only on create blog entries and edtiting blog entries. The problem is, the path for editing blogs is node/*/edit. I tried the code above, but it's not working for me. Any other ideas?

jillelaine’s picture

I'm sorry you are having trouble. I tested this code on drupal module tinymce-4.7.x-1.x-dev.tar.gz and not on other releases of TinyMCE. http://drupal.org/node/18803/release If you have a different version of the TinyMCE module, this may not work.

The code to have TinyMCE available on blogs (and ONLY blogs, whether new or existing) should be:

<?php
$match = FALSE;

/* this section controls visibility on EXISTING content */

$types = array('blog' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}

/* this section controls visibility on NEW content */

if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/blog")
{ $match = TRUE;}

return $match;
?>

Be sure to copy ALL of the code above into your TinyMCE settings visibility section. The above code works for me on my Drupal 4.7.4 installation.

If want TinyMCE available for a different 'content type', you need to replace the word "blog" in the above code with the real name of the other 'content type'.

To learn the real name of a 'content type', go to: create content > 'other_content_type'. After the page loads, the last 'word' in the URL is the real name of the 'other_content_type'.

For instance, the URL for create content > book page is http://www.example.com/node/add/book. Therefore, "book" (and not "book page") is the real name of the 'content type' "book page".

So the code to have TinyMCE available on "book pages" (and ONLY "book pages", whether new or existing) is:

<?php
$match = FALSE;

/* this section controls visibility on EXISTING content */

$types = array('book' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}

/* this section controls visibility on NEW content */

if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/book")
{ $match = TRUE;}

return $match;
?>

Determine the name for any 'content types' you would like to manage in this way and modify the code. I hope this explanation helps.

belbo’s picture

It's better to replace
...
if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/book")
{ $match = TRUE;}
...
with
...
if (strpos(request_uri(),"node/add/book"))
{ $match = TRUE;}
...
Because with some Drupal settings you have
"?q=..." and not "/..."

jillelaine’s picture

the above code replacement works in my testbed.

so the updated code to have TinyMCE be available on blogs, books, and pages (and ONLY on blogs, books, and pages) is:

<?php
$match = FALSE;

/* this section controls visibility on EXISTING content */

$types = array('blog' => 1, 'book' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
  $match = TRUE;
}
}

/* this section controls visibility on NEW content */

if (strpos(request_uri(),"node/add/blog"))
{ $match = TRUE;}
if (strpos(request_uri(),"node/add/book"))
{ $match = TRUE;}
if (strpos(request_uri(),"node/add/page"))
{ $match = TRUE;}

return $match;
?>
konsumer’s picture

This seems to accomplish what you are trying to do, in a more generic way (exclude just webform type) plus, I think it's a tiny bit more efficient.


/* get types, except webform */
$types=node_get_types();
unset($types['webform']);
$types=array_keys($types);

/* this section controls visibility on EXISTING content */

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  if (in_array($type, $types)) {
    return TRUE;
  }
}

/* this section controls visibility on NEW content */
foreach($types as $type){
  if (strpos(request_uri(),"node/add/$type")){
    return TRUE;
  }
}

// not matched
return FALSE;