A Quick Fix for Drupal 7 (Taxonomy Term)

If you build websites with Drupal CMF (Content Management Framework) and need to allow some set of users to add new vocabulary term, Drupal core allows you to do this easily. However, the interface might be confusing to an ordinary user who is not used to the Drupal framework.
To add a new vocabulary term in Drupal, all you need to do is click on "add Term" as shown in the image above. But in the real practical sense, users expect to see something like "Add a new type of shirt" or "Add a new type of car", where shirt and car are vocabularies. You can't do this with any existing configuration in Drupal. This is why we have written this short fix. The code is available below.
We simply overide the taxonomy core module by calling the hook_menu_alter(), and pass on an argument to the title using "title arguments" with our own defined "title callback", while reusing the arguments.
All you need to do is to create a module and drop the code below in your_module.module file. Enable it, and CLEAR ALL CACHES. Sweet, it works! With this fix, you can always change the text ('Add new @vocab_name') from the code or by using the string_overide module. Do not forget to create your .info file first.
<?phpfunction my_fixes_menu_alter(&$items){$items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/add']['title callback'] = 'current_vocab';$items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/add']['title arguments'] = array(3);}function current_vocab($arg){$vocab_name = check_plain($arg->name);return t('Add new @vocab_name', array('@vocab_name' => $vocab_name));}
Add new comment