How would YOU disable TinyMCE for a particular node type? TinyMCE's inclusion and exclusion is on a per page.

node/*
user/*
comment/*

The node type I'm trying to exclude is Webforms (which appear within "nodes" so is included in node/*). I tried using TinyMCE's "Show if the following PHP code returns TRUE" with:

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

But alas, no go -- it always considers it NOT a webform eventhough I'll view a webform (Mayhaps $type is not resolving within this tinyMCE php node context or there's another way).

Does ANYONE have an idea? Pleeeeeeeeeease... I have a community of people using my drupal site and I really really want to give them rich text features without screwing up the webforms that are heavily used as well. And I'm at a loss at this point....

Thanks!

Comments

K-O-N-G’s picture

Try use this

<? 
  // disable tinymce in page
  if($_GET['q']=="node/add/page") return FALSE;
   else return true;
?>
garym’s picture

Thanks, that got me thinking on using the "add" & "edit" part of the paths for inclusion. I now have it MOSTLY working as I want it with the setting "Show on only the listed pages" as:

node/*/edit
node/add/story
node/add/page
node/add/book
node/add/forum

The concept is that you ONLY want TinyMCE to show when editing & adding nodes. In this way, when people are filling out the webform, they don't see TinyMCE. Unfortunately, when "editing" a webform, you still see TinyMCE which does nothing as webform "description" and other text areas don't retain formatting, so it is misleading. But good enough to upload as most users do not edit webforms. Thanks....

shawn.sh’s picture

I had this problem as well and I used a combination of the above code as well as some logic in the page.tpl file to get the "editing" part disabled for certain node types as well.

In the TinyMCE visibility settings I added to
"Show on only the listed pages"

node/add/story
node/add/page

As you can see I left out the edit parts... for the "edit" pages I copied the TinyMCE JavaScript from the source of the "add" page and added the code below to the page.tpl in the head.

<?php 
if (($node->type=='story' || $node->type=='page')  && arg(2)=='edit'){ 

/// TinyMCE JavaScript goes here - it's a bit long to post

}
?>

I know the code is probably inefficient as hell because I'm no php coder and it's late, but it works. Hopefully it helps some lost soul still on 4.7 like I am.

lmakarov’s picture

Use this code

/**
 * Implementation of hook_elements().
 */
function tinymce_elements() {
  /********************************************************************/
  //disable tinymce for listed node types
  $exclude_list = array('webform');
  
  //node add
  if (arg(0) == 'node' && arg(1) == 'add' && in_array(arg(2), $exclude_list)) {
    return;
  }
  
  //node edit
  if (arg(0) == 'node' && (is_numeric(arg(1)))) {
      $node = node_load(arg(1));
    if (in_array($node->type, $exclude_list)) {
      return;
    }
  }
  /********************************************************************/
  
  $type = array();

.............
alexxed’s picture

I had the problem myself. You need to load the $node to have it available in the eval. It may do query+ but hey, it's just on the add/edit page, shouldn't slow you down.

Example: Show tinymce only for story and image type.

<?php 
    $node = node_load(arg(1)); 
    if (!$node && strstr($_REQUEST['q'], 'node/add')) 
        $node_type=preg_replace('/[a-z]+\/node\/add\//', '', $_REQUEST['q']); 
    else 
        $node_type=$node->type; 
    return in_array($node_type, array('story', 'image', 'page', 'glossary_term', 'poll')); 
?>

Note that a separate code is needed in case you are adding nodes.

pluess’s picture

This only works if you have nice URLs and no port number in your URL. The following solution is independant from the beginning of the URL:

	  $url = $_REQUEST['q'];
	
	  if ($end=strstr($url, 'node/add/')) {
	    $parts = split('/', $end);
	    $node_type = $parts[2];
	  }
	  else {
	    $node = node_load(arg(1));
	    $node_type=$node->type;
	  }
	  return in_array($node_type, array('page', 'event'));
Anonymous’s picture

A bunch of other things I tried should have worked, but didn't, so I finally did this in Drupal 5:

<?php
if (!strstr($_REQUEST['q'], 'admin')) {
  $mynode = node_load($params=array('nid' => arg(1)));
  if (!$mynode && arg(0) == 'node' && arg(1) == 'add') {
  $node_type = arg(2);
  }
  else {
  $node_type=$mynode->type;
  }
  return !in_array($node_type, array('book'));
}
else {
  return FALSE;
}
?>

Doug Gough

ImageX Media

kalbun’s picture

What I really wanted to do was to disable TinyMCE ONLY while adding or editing a Webform field.

The URL in these cases is in the form:

http://.../components/...

So I added in the TinyMCE this simple line:

  return (
    strstr($_REQUEST['q'], '/components/') == "" &&
    strstr($_REQUEST['q'], 'admin/') == ""
  );

And it seems to work.