Disabling tinymce for trackbacks text area
tng@neuralgourm... - July 10, 2006 - 00:50
I'm sure I'm being an idiot here, but how would I disable tinymce from loading in the text area for trackbacks?
I'm sure I'm being an idiot here, but how would I disable tinymce from loading in the text area for trackbacks?
options
Interesting problem, you are looking for a means to disable Tinymce by referral or something? Couldn't tell you how to do that... options that I can offer, turn Tinymce off for the anonymous role. Or the solution that I use is to have Tinymce off by default and set it to show a link to enable rich text, I think that solution rocks.
------------------------------------------------------------------------------------------
"You can always find the storm by listening for the Thunder."
function
function tinymce_textarea($op, $textarea_name) {
//###################################################
//break = we edit it, return = we don't
switch ($textarea_name) {
case 'body':
break;
case 'caption': //on images
return;
case 'components':
return;
case 'ec_order_overview':
return;
case 'help': //on project_project
break;
case 'log':
return;
case strpos($textarea_name,'nodewords')==0:
return;
case 'pages':
return;
case strpos($textarea_name,'payment')==0:
return;
case strpos($textarea_name,'shipping')==0:
return;
case 'signature':
break;
case strpos($textarea_name,'theme_setting')==0:
return;
default:
//we log any new types so they may be added to the code
watchdog( 'tinyMCE', t('unknown textarea name: ').$textarea_name , WATCHDOG_NOTICE);
return;
}
...etc ...
Thanks. That looks like exactly what I want.
Which file is that in? I looked in tinymce.module and the javascript files in modules/tinymce/tinymce/jscripts/tinymce and did not find it. Or should I add that function to tinymce.module? What function should I call it from?
There really should be a way to control the loading of TinyMCE on a per textarea basis in the Drupal tinymce settings.
I see TinyMCE has a way of controlling display based on a block of PHP code returning true. Could we control whether or not TinyMCE displays on a per textarea basis from there?
Neural Gourmet | Feed Your Brain
Carnival of the Liberals -- Thinking Liberally
That function is in tinymce.module 4.6.0
It's in my tinymce.module :-)
Just insert this code at the start of the function and edit to whatever text areas you do/don't want.
But see comments below re using a theme-based approach
cheers
Rob
I'd like to be able to control TinyMCE on a per-textarea basis
My site is primarily a group blog so I use the trackback module. The problem is that the TinyMCE settings only control whether or not it displays on a page-level basis. But I want TinyMCE to show for the body and excerpt textareas, but not the trackback textarea. Hopefully I'm making sense.
Neural Gourmet | Feed Your Brain
Carnival of the Liberals -- Thinking Liberally
Yeah, let us know when you develop it
I'd be interested in looking at your solution to this tng, when you develop it please let us know.
----------------------------------------------------------------------------------
"You can always find the storm by listening for the Thunder."
OK, got it sorted.
This turns out to be really easy but the documentation is not very clear.
The documentation says about function theme_tinymce_theme:
That's not the case though. There is no need to add this function to your template file, it already exists in tinymce.module. All that's required to disable loading of TinyMCE for the trackback text area is to add one extra line to the first set of case tests in theme_tinymce_theme, like this:
function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {switch ($textarea_name) {
// Disable tinymce for these textareas
case 'log': // book and page log
case 'img_assist_pages':
case 'caption': // signature
case 'pages':
case 'access_pages': //TinyMCE profile settings.
case 'user_mail_welcome_body': // user config settings
case 'user_mail_approval_body': // user config settings
case 'user_mail_pass_body': // user config settings
case 'synonyms': // taxonomy terms
case 'description': // taxonomy terms
case 'trackback_urls': // trackback module textarea
unset($init);
break;
If someone knows of a better way of doing this, please let me know.
Neural Gourmet | Feed Your Brain
Carnival of the Liberals -- Thinking Liberally
Oh cool
I missed these posts when i wrote previous reply, and back when i wrote the above hack i didn't understand theming :-)
the whole point of the theme_... functions is so you don't hack tinymce.module.
So don't change theme_tinymce_theme at all.
Say you are using a them called fred. In YOUR fred.theme module, you put a function fred_tinymce_theme and THAT function will automatically replace theme_tinymce_theme. So you put your textarea override code in function fred_tinymce_theme in fred.theme, not in theme_tinymce_theme in tinymce.module.
The upside is that there are no changes in the base tinymce.module, just in fred.theme that you change anyway. the drawback of the theme-based approach is that you have to set it for each theme and if you add a new theme you may forget. in some ways I prefer the hack in the base module.
Oh, very cool. Thank you.
So, for Neural Gourmet where I'm using the adc theme right now I just need to put that function in my adc.theme module and call it adc_tinymce_theme instead of theme_tinymce_theme and it will override the TinyMCE settings. That's very slick. Still, it would really be nice if we had this capability in the admin/settings/tinymce. Thanks so much for the clarification. I really appreciate it.
Neural Gourmet | Feed Your Brain
Carnival of the Liberals -- Thinking Liberally
that's the theory
...haven't had time to try it yet, nor will i for weeks the way things are going. let us know how you get on
Yes I agree.. Rather do it
Yes I agree..
Rather do it on the theme level:
I added the following to my template.php file:
function mythemename_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
switch ($textarea_name) {
// Disable tinymce for these textareas
case 'log': // book and page log
case 'img_assist_pages':
case 'caption': // signature
case 'pages':
case 'access_pages': //TinyMCE profile settings.
case 'user_mail_welcome_body': // user config settings
case 'user_mail_approval_body': // user config settings
case 'user_mail_pass_body': // user config settings
case 'synonyms': // taxonomy terms
case 'description': // taxonomy terms
case 'workflow_comment': // workflow state comment
unset($init);
break;
// Force the 'simple' theme for some of the smaller textareas.
case 'signature':
case 'site_mission':
case 'site_footer':
case 'site_offline_message':
case 'page_help':
case 'user_registration_help':
case 'user_picture_guidelines':
$init['theme'] = 'simple';
foreach ($init as $k => $v) {
if (strstr($k, 'theme_advanced_')) unset($init[$k]);
}
break;
}
}
note that this was done to disable tinymce on comment fields (and not trackbacks)
Same concept though
Forgot the return statement
Return added for completeness. Won't work without it.
function instatone2_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
switch ($textarea_name) {
// Disable tinymce for these textareas
case 'log': // book and page log
case 'img_assist_pages':
case 'caption': // signature
case 'pages':
case 'access_pages': //TinyMCE profile settings.
case 'user_mail_welcome_body': // user config settings
case 'user_mail_approval_body': // user config settings
case 'user_mail_pass_body': // user config settings
case 'synonyms': // taxonomy terms
case 'description': // taxonomy terms
unset($init);
break;
// Force the 'simple' theme for some of the smaller textareas.
case 'signature':
case 'site_mission':
case 'site_footer':
case 'site_offline_message':
case 'page_help':
case 'user_registration_help':
case 'user_picture_guidelines':
$init['theme'] = 'simple';
foreach ($init as $k => $v) {
if (strstr($k, 'theme_advanced_')) unset($init[$k]);
}
break;
}
// Always return $init
return $init;
}
case 'log': // book and
case 'log': // book and page logRight.. now how do I figure this one out... I added a new block with PHP code (where I obviously do not want to load TinyMCE)
How do I know the name of the textarea? ...like "Log" in the above example...
I did a "view page source" on the page and I see:
<textarea cols="60" rows="15" name="edit[body]"Is that the name I use?
Like:
case 'edit[body]': // disable for custom block code????
Thanks
Associate an editor with a filter
others will correct me if I am wrong: I think the main body text is always called that, PHP or not. The way i know to deal with PHP is to associate the editor with a filter. Then the editor is sincluded for some input formats but not for those which also include the PHP evaluator (or any opther formats where you don't want it). I haven't done it for TinyMCE (yet) but here's how I did it for FCKEditor (this is 4.6 code):
function fckeditor_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('FCKEditor'));
case 'description':
return t('Makes FCKEditor (more discretely known as "the rich text editor") available for this format.');
case 'prepare':
return $text;
case 'process':
return $text;
default:
return $text;
}
}
function fckeditor_filter_tips($delta, $format, $long = false) {
if ($long) {
$message = 'The rich text editor is available for this format if <ul><li>the editor has been enabled by your system administrator</li><li>it is turned on for this type of field (body, log etc...)</li><li>it is not turned off for this path (i.e. the "command" that follows the site URL)</li><li>you have not temporarily disabled it with the checkbox just above the editor (or where it would appear)</li><li>your role (user type) have sufficient access permission to the editor</li><li>you are using a compatible browser (this current browser is ';
if ( ! fckeditor_is_compatible_client() ) {
$message .= 'NOT ';
}
$message .= ' compatible)</li></ul><br />Phew!<br \>Use all the facilities of the editor except images. For that capability please use the image icon below the text box';
return $message;
} else {
return t('The rich text editor is available for this format if... (see ' .
l('here', 'filter/tips' ).
')' );
}
}
name="relatedlinks_fieldset[relatedlinks]"
In reply to jacauc:
I had the same issue after I installed the relatedlinks module. The textarea to manually define links comes up in page source as name="relatedlinks_fieldset[relatedlinks]".
I eventually found that what works is:
case 'relatedlinks-fieldset-relatedlinks': //related links
Not sure why.
Instructions Wrong?
So the instructions in the module's install.txt are wrong?
"Once TinyMCE is enabled, the default behavior is that all textareas will use TinyMCE for all users. The admin can change these defaults at administer > settings > tinymce"
I can't seem to find those defaults in the TinyMCE profiles.
this code works for me great...
function corporate_website_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
switch ($textarea_name) {
// Disable tinymce for these textareas
case 'log': // book and page log
case 'img_assist_pages':
case 'caption': // signature
case 'pages':
case 'trackback-urls': // trackback module textarea
case 'access_pages': //TinyMCE profile settings.
case 'user_mail_welcome_body': // user config settings
case 'user_mail_approval_body': // user config settings
case 'user_mail_pass_body': // user config settings
case 'synonyms': // taxonomy terms
case 'description': // taxonomy terms
unset($init);
break;
// Force the 'simple' theme for some of the smaller textareas.
case 'signature':
case 'site_mission':
case 'site_footer':
case 'site_offline_message':
case 'page_help':
case 'user_registration_help':
case 'user_picture_guidelines':
$init['theme'] = 'simple';
foreach ($init as $k => $v) {
if (strstr($k, 'theme_advanced_')) unset($init[$k]);
}
break;
}
// Always return $init
return $init;
}
sharma chelluri
tried to hide tinyMCE from
tried to hide tinyMCE from trackback-field in drupal 5.2 - and it seems to need a '-' instead of '_' as a separator..
case 'trackback-urls': // hide from trackback-fieldinstead of
case 'trackback_urls': // hide from trackback-field..dont know about the other fields yet, the trackback-field was the one I wanted to disable first..
greetz, t..
___________________________
my pictures: www.bilderbook.org
This could be due to
This could be due to Pathauto replacing all underscores with dashes.
Ok, but can you hide the "enable rich-text" link as well?
I've been able to avoid tinymce loading on my "terms and conditions" text box in the user profile using the technique explained on this page. The terms and conditions text box thus loads as a protected text area (users can't change the terms and conditions). Tinymce is not on for this field, but there is an "enable rich-text" link. If the user clicks it, tinymce is then loaded for the text area, and my terms and conditions becomes unprotected again!
Is there anyway to avoid users being able to turn on tinymce using this link?
Thanks!
STeve
any chance there is a way to
frorget it i got it thanks
Even easier
View HTML source from TinyMCE and remove the "< p >" and "< / p >" tags from the text. Then it works.
disabling tinymce for cck fields
I just spent an hour or so struggling to figure out the proper naming convention for cck text fields. Thanks to some superb help from a friend, I finally found it.
Here's a sample piece of code to disable a cck textarea field:
case 'field-cck-field-name-0-value':Just pop that in to the the theme_tinymce function, and away you go!
need advise
hi, i try to solve the tinymce problem for my website. i have cck field name "field_description".
based on your example, i create this
case 'field-cck-field-description-0-value':then i paste it in my template.php along with the snippet above
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
switch ($textarea_name) {
// Disable tinymce for these textareas
case 'field-cck-field-description-0-value': //cck field name field_description
unset($init);
break;
}
// Always return $init
return $init;
}
the tinymce still on for that text area. please advise if i have make any mistake
thanks
for Drupal 5.1 + CCK
use
case 'field-description-0-value'(despite original id of textarea in page source)
thank you
thank you for the help. i manage to disable tinymce for the textarea.
I cant get this to work with 6.2
I cant get this working with 6.2, did this change? The name looks the same.
Thanks
Enable for 'body' textarea only?
I'd prefer to work the other way around, only enable TinyMCE for certain fields. Is that possible?
Oops...
Sorry I appear to have switched my brain off momentarily there. For those interested...
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {switch ($textarea_name) {
// Enable tinymce for these textareas
case 'body':
break;
// Disable tinymce for all other textareas
default:
unset($init);
}
// Always return $init
return $init;
}
Cannot disable / enable
Hi Guys
I just spent several hours in trying to disable or enable TinyMCE for particular text areas. I'm for example using the module "Related Links" and wanna disable the editor there. Unfortunately, i did not succeed. I've read the README.txt provided with the TinyMCE module and pasting the phptemplate_tinymce_theme() function from the README file into my template.php does not do anything.
I even tried the method described above:
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {switch ($textarea_name) {
// Enable tinymce for these textareas
case 'body':
break;
// Disable tinymce for all other textareas
default:
unset($init);
}
// Always return $init
return $init;
}
?>
but this does not do anything... Any help?
Regards,
Peter.
More info?
Not sure I can be much help but might help to know more information about your set up. Are you using Drupal 5? Which version of the module etc?
More information
- latest version of drupal (5.1)
- latest version of both the TinyMCE module and TinyMCE itself.
Bullet proof way of finding the field name
This was bugging me for ages but I figured how to find the field name. First enable TinyMCE and make sure the controls are showing in the field you don't want them to show. Then go to view source. At the top you should see some script like this:
</script><style type="text/css" media="all">.mceEditor img { display: inline; }</style>
<script type="text/javascript">
tinyMCE.init({
mode : "exact",
theme : "advanced",
relative_urls : false,
document_base_url : "/",
language : "en",
safari_warning : false,
entity_encoding : "raw",
verify_html : true,
preformatted : false,
convert_fonts_to_styles : true,
plugins : "emotions,table",
theme_advanced_toolbar_location : "bottom",
theme_advanced_toolbar_align : "center",
theme_advanced_path_location : "bottom",
theme_advanced_resizing : true,
theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
theme_advanced_buttons1 : "bold,italic,underline,justifyleft,justifycenter,justifyright,bullist,numlist,outdent,indent,undo,link,unlink,fontselect,fontsizeselect,image,forecolor,emotions,tablecontrols",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
content_css : "/themes/box_grey/style.css",
elements : "edit-imageurl"
});
</script>
The last part we're interested in is
elements : "edit-imageurl"Now simply remove the 'edit-' at the beginning and that is your field name! So in your template.php it would like like
case 'imageurl': // imageurlHope this helps some people,
Neil
- Connecting Language Learners
www.huitalk.com
Just add the following
Just add the following statement temporarily:
<?phpfunction phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
drupal_set_message($textarea_name);
switch ($textarea_name) {
.....
?>
It will list all the names of the textareas!
-----------------------------------------
Joep
CompuBase, Drupal websites and design
And if I want just "simple"
And if I want just "simple" theme for creating pages (node/add/page)?..
What I have to add here?
// Force the 'simple' theme for some of the smaller textareas.case 'signature':
case 'site_mission':
case 'site_footer':
case 'site_offline_message':
case 'page_help':
case 'user_registration_help':
case 'user_picture_guidelines':
$init['theme'] = 'simple';
foreach ($init as $k => $v) {
if (strstr($k, 'theme_advanced_')) unset($init[$k]);
}
break;
}
Disable TinyMCE based on node-type
We had the requirement to not only disable TinyMCE based on field names, but also to disable it for certain node-types. Since I was using a function in template.php to disable based on field-names (as per the instructions), I just added some logic to it. In this case I'm whitelisting node types - you could just as easily blacklist instead.
<?php
function mytheme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
# enter the node types that will use TinyMCE
$allowed = array('blog','event','story');
//check for node-edit
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)));
if (!in_array($node->type,$allowed)) {
unset($init);
return $init;
}
}
//check for node-add
if(arg(0) == 'node' && arg(1) == 'add') {
if(!in_array(arg(2),$allowed)) {
unset($init);
return $init;
}
}
switch ($textarea_name) {
... the rest of the logic from tinymce.modules README.TXT
?>
Hey! Thanks for the code,
Hey! Thanks for the code, although I do not quite understand how !in_array() works and why it was a little different from http://drupal.org/node/134425
But just so anyone wants to accomplish what you did, there is no need to add that code in a template file. Just enter it into the Visibilty field of a TinyMCE profile and set it to "Show if the following PHP code returns TRUE (PHP-mode, experts only)." Then enter the following code:
<?php
$allowed = array('page', 'blog');
//check for node-edit
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)));
if (!in_array($node->type,$allowed)) {
return false;
} else return true;
}
//check for node-add
if(arg(0) == 'node' && arg(1) == 'add') {
if(!in_array(arg(2),$allowed)) {
return false;
} else return true;
}
?>
This is all really confusing
This is all really confusing to me. And this is the last step for site completion and I didn't see it coming.
When generating a node, my users have the option to post a custom signature as opposed to the one in their profile.
The TinyMCE editor show for the CCK field "signature"
however when it is displayed it doesn't formate it shows all the html tags.
I dont know how to fix it.
I want my users to be able to use the editor on their signatures but the code to not show
And to blacklist certain pages (like webforms), do the reverse
I wanted to keep tinymce from showing up in the editing pages for webforms, but still have it show up for all other types, including comments. Here's a slight variation of the code above (with some help from http://drupal.org/node/64135#comment-271177), to go in the "Show if the following PHP code returns TRUE (PHP-mode, experts only)" area of the tinymce settings for a given profile.
<?php
$match = false;
$blacklist = array('webform');
//check for node-edit
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)));
if (!in_array($node->type,$blacklist)) {
$match = true;
}
}
//check for comments
$url = request_uri();
if (strpos($url, "comment")) {
$match = true;
}
//check for node-add
if(arg(0) == 'node' && arg(1) == 'add') {
if(!in_array(arg(2),$blacklist)) {
$match = true;
}
}
return $match;
?>
:(
<? phpinfo();?>
alert("spam");
:(
Perfect. This is exactly how
Perfect. This is exactly how I was able to remove tinymce from fighting with custom content types!
Thanks
Derrick
subscribing
subscribing
I don't know why this
I don't know why this happens but when I request a page for webform module i.e. node/add/webform or node/nid/edit (when that node is a webform) I get a white screen with "disable rich-text" twice.
My fix was to use theme_tinymce_theme and add in some logic of my own:
<?php// Disable TinyMCE for webform nodes.
$nids = array(60, 53, 58, 63); // webform nids
if (in_array(arg(1), $nids)) {
unset($init);
}
?>
I used these settings in TinyMCE visibility (show on only these pages):
node/add/content-typenode/add/page
node/*/edit
Replace node/add/content-type with a list of your own custom content types. The reason I use these visibility settings is because node/add/webform caused the white screen.