Setting TinyMCE visibility for translatable content types that have names with spaces in Drupal

This is a little caveat for you in case you work with TinyMCE and the i18n module.

If you like to restrict the TinyMCE form to only appear on the node add and edit forms (node/add, node/edit/[id]), and you have spaces in your content type name, there's a slightly different drupal path 'behaviour' for the original node and the translated node.

The normal drupal path for adding nodes to drupal is node/add/[contenttype]. If the content type name contains spaces, the drupal path for adding a new node contains the content type name with spaces replaced by dashes. So you'll have something like node/add/blog-post if your content type is 'blog_post'.

That is only true for adding a new node that is not a translation of another node. If you say 'create translation' to add the translation for a node then the content type name in the drupal path hasn't spaces replaced by dashes but by underscores. So you'll have node/add/blog_post in our example.

Here is the code for the example 'blog post' content type. For completness' sake I have added the node edit case too.

<?php
if(arg(0) == 'node' && arg(1) == 'add' && (arg(2) == 'blog-post' || arg(2) == 'blog_post')) {
  return TRUE;
} 
else if(arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
  $node = node_load(arg(1));
  if($node->type == 'blog_post') {
    return TRUE;
  } else {
    return FALSE;
  } 
} 
else {
  return FALSE;
}
?>
Written on February 07, 2008 at 19:15, tagged as caveats, Drupal, i18n, modules, TinyMCE

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

About

drupalcoder.com is a blog on all things Drupal in specific and LAMP on OS X in general. It is maintained by Davy Van Den Bremt, a Belgian (Drupal) web developer and designer living in Ghent. The goal of this blog is to log all interesting things that have crossed the writer's path while developing Drupal sites. You can read all about Davy's professional activities on his LinkedIn profile. If you want to get in touch, use the contact form.