User login

Clean up and rationalize Drupal core Taxonomy Term Add and Edit form

I can't believe no one has done this!

Simplify the taxonomy interface for administrators by removing the taxonomy related terms box...

drupal taxonomy hide related terms
drupal form tweaks remove related terms

The commit message upon completion...

"Clean taxonomy term add / edit form by removing related terms and moving parents from the closed advanced fieldset to the open identification fieldset if the vocabulary has already been made hierarchical."

And the code:

<?php
/**
 * Clean taxonomy term add/edit form chiefly by removing term relations.
 *
 * Also takes parents out of the advanced fieldset if the vocabulary is
 * already hierarchical.
 *
 * Implements hook_form_FORM_ID_alter().
 */
function agaricgenarts_form_taxonomy_form_term_alter(&$form, $form_state) {
 
// @TODO confirm unsetting is safe.  It may delete existing relations.
 
unset($form['advanced']['relations']);
  if (
$form['#vocabulary']['hierarchy']) {
   
$form['identification']['parent'] = $form['advanced']['parent'];
   
$form['identification']['parent']['#weight'] = 5;
    unset(
$form['advanced']['parent']);
  }
}
?>

Figured out using the tried and true orientation method of a hook_form_alter and drupal_set_message:

<?php
function agaricgenarts_form_alter(&$form, $form_state, $form_id) {
 
drupal_set_message('<pre>'.var_export($form_id,TRUE).'</pre>'); //@debug
 
drupal_set_message('<pre>'.var_export($form,TRUE).'</pre>'); //@debug
}
?>

Which gives us this exciting information:

'taxonomy_form_term'

<?php
array (
 
'#term' =>
  array (
   
'name' => '',
   
'description' => '',
   
'tid' => NULL,
   
'weight' => 0,
   
'parent' =>
    array (
    ),
  ),
 
'#vocabulary' =>
  array (
   
'vid' => '3',
   
'name' => 'Effects',
   
'description' => '',
   
'help' => '',
   
'relations' => '1',
   
'hierarchy' => '1',
   
'multiple' => '0',
   
'required' => '1',
   
'tags' => '0',
   
'module' => 'taxonomy',
   
'weight' => '0',
   
'nodes' =>
    array (
     
'effect' => 'effect',
    ),
  ),
 
'identification' =>
  array (
   
'#type' => 'fieldset',
   
'#title' => 'Identification',
   
'#collapsible' => true,
   
'name' =>
    array (
     
'#type' => 'textfield',
     
'#title' => 'Term name',
     
'#default_value' => '',
     
'#maxlength' => 255,
     
'#description' => 'The name of this term.',
     
'#required' => true,
    ),
   
'description' =>
    array (
     
'#type' => 'textarea',
     
'#title' => 'Description',
     
'#default_value' => '',
     
'#description' => 'A description of the term. To be displayed on taxonomy/term pages and RSS feeds.',
    ),
  ),
 
'advanced' =>
  array (
   
'#type' => 'fieldset',
   
'#title' => 'Advanced options',
   
'#collapsible' => true,
   
'#collapsed' => true,
   
'parent' =>
    array (
     
'#type' => 'select',
     
'#title' => 'Parents',
     
'#default_value' =>
      array (
      ),
     
'#options' =>
      array (
       
'' => '',
       
0 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
1 => 'Lighting',
          ),
        )),
       
1 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
4 => '-Glints & Glares',
          ),
        )),
       
2 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
3 => '-Glow Effects',
          ),
        )),
       
3 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
2 => '-Light Effects',
          ),
        )),
       
4 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
19 => 'Particle Effects',
          ),
        )),
       
5 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
5 => 'Stylize',
          ),
        )),
       
6 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
6 => '-Film Effects & Grain',
          ),
        )),
      ),
     
'#description' => 'Parent terms.',
     
'#multiple' => 1,
     
'#size' => 8,
     
'#weight' => -15,
     
'#theme' => 'taxonomy_term_select',
    ),
   
'relations' =>
    array (
     
'#type' => 'select',
     
'#title' => 'Related terms',
     
'#default_value' =>
      array (
      ),
     
'#options' =>
      array (
       
'' => '',
       
0 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
1 => 'Lighting',
          ),
        )),
       
1 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
4 => '-Glints & Glares',
          ),
        )),
       
2 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
3 => '-Glow Effects',
          ),
        )),
       
3 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
2 => '-Light Effects',
          ),
        )),
       
4 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
19 => 'Particle Effects',
          ),
        )),
       
5 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
5 => 'Stylize',
          ),
        )),
       
6 =>
       
stdClass::__set_state(array(
          
'option' =>
          array (
           
6 => '-Film Effects & Grain',
          ),
        )),
      ),
     
'#description' => NULL,
     
'#multiple' => 1,
     
'#size' => 8,
     
'#weight' => -15,
     
'#theme' => 'taxonomy_term_select',
    ),
   
'synonyms' =>
    array (
     
'#type' => 'textarea',
     
'#title' => 'Synonyms',
     
'#default_value' => '',
     
'#description' => 'Synonyms of this term, one synonym per line.',
    ),
   
'weight' =>
    array (
     
'#type' => 'textfield',
     
'#title' => 'Weight',
     
'#size' => 6,
     
'#default_value' => 0,
     
'#description' => 'Terms are displayed in ascending order by weight.',
     
'#required' => true,
    ),
  ),
 
'vid' =>
  array (
   
'#type' => 'value',
   
'#value' => '3',
  ),
 
'submit' =>
  array (
   
'#type' => 'submit',
   
'#value' => 'Save',
  ),
 
'destination' =>
  array (
   
'#type' => 'hidden',
   
'#value' => 'admin/content/taxonomy/3/add/term',
  ),
 
'#parameters' =>
  array (
   
0 => 'taxonomy_form_term',
   
1 =>
    array (
     
'storage' => NULL,
     
'submitted' => false,
     
'post' =>
      array (
      ),
    ),
   
2 =>
   
stdClass::__set_state(array(
      
'vid' => '3',
      
'name' => 'Effects',
      
'description' => '',
      
'help' => '',
      
'relations' => '1',
      
'hierarchy' => '1',
      
'multiple' => '0',
      
'required' => '1',
      
'tags' => '0',
      
'module' => 'taxonomy',
      
'weight' => '0',
      
'nodes' =>
      array (
       
'effect' => 'effect',
      ),
    )),
  ),
 
'#build_id' => 'form-bfe00fd512c1a743d50193b463054890',
 
'#type' => 'form',
 
'#programmed' => false,
 
'form_build_id' =>
  array (
   
'#type' => 'hidden',
   
'#value' => 'form-bfe00fd512c1a743d50193b463054890',
   
'#id' => 'form-bfe00fd512c1a743d50193b463054890',
   
'#name' => 'form_build_id',
  ),
 
'#token' => 'taxonomy_form_term',
 
'form_token' =>
  array (
   
'#id' => 'edit-taxonomy-form-term-form-token',
   
'#type' => 'token',
   
'#default_value' => 'd9161f7567a469efdb823688fb96a3a1',
  ),
 
'form_id' =>
  array (
   
'#type' => 'hidden',
   
'#value' => 'taxonomy_form_term',
   
'#id' => 'edit-taxonomy-form-term',
  ),
 
'#id' => 'taxonomy-form-term',
 
'#description' => NULL,
 
'#attributes' =>
  array (
  ),
 
'#required' => false,
 
'#tree' => false,
 
'#parents' =>
  array (
  ),
 
'#method' => 'post',
 
'#action' => '/genarts/admin/content/taxonomy/3/add/term',
 
'#validate' =>
  array (
   
0 => 'taxonomy_form_term_validate',
  ),
 
'#submit' =>
  array (
   
0 => 'taxonomy_form_term_submit',
  ),
 
'#after_build' =>
  array (
   
0 => 'checkall_form_after_build',
  ),
)
?>

The end.

For miscellaneous interest... the form listing all the available vocabularies at admin/content/taxonomy:

<?php
array (
 
'#tree' => true,
 
2 =>
  array (
   
'#vocabulary' =>
    array (
     
'vid' => '2',
     
'name' => 'Clients',
     
'description' => '',
     
'help' => 'Autocomplete ',
     
'relations' => '1',
     
'hierarchy' => '0',
     
'multiple' => '1',
     
'required' => '0',
     
'tags' => '1',
     
'module' => 'taxonomy',
     
'weight' => '0',
     
'nodes' =>
      array (
       
'film' => 'film',
       
'story' => 'story',
      ),
    ),
   
'name' =>
    array (
     
'#value' => 'Clients',
    ),
   
'types' =>
    array (
     
'#value' => 'Film, Customer story',
    ),
   
'weight' =>
    array (
     
'#type' => 'weight',
     
'#delta' => 10,
     
'#default_value' => '0',
    ),
   
'edit' =>
    array (
     
'#value' => 'edit vocabulary',
    ),
   
'list' =>
    array (
     
'#value' => 'list terms',
    ),
   
'add' =>
    array (
     
'#value' => 'add terms',
    ),
  ),
 
3 =>
  array (
   
'#vocabulary' =>
    array (
     
'vid' => '3',
     
'name' => 'Effects',
     
'description' => '',
     
'help' => '',
     
'relations' => '1',
     
'hierarchy' => '1',
     
'multiple' => '0',
     
'required' => '1',
     
'tags' => '0',
     
'module' => 'taxonomy',
     
'weight' => '0',
     
'nodes' =>
      array (
       
'effect' => 'effect',
      ),
    ),
   
'name' =>
    array (
     
'#value' => 'Effects',
    ),
   
'types' =>
    array (
     
'#value' => 'Effect',
    ),
   
'weight' =>
    array (
     
'#type' => 'weight',
     
'#delta' => 10,
     
'#default_value' => '0',
    ),
   
'edit' =>
    array (
     
'#value' => 'edit vocabulary',
    ),
   
'list' =>
    array (
     
'#value' => 'list terms',
    ),
   
'add' =>
    array (
     
'#value' => 'add terms',
    ),
  ),
 
4 =>
  array (
   
'#vocabulary' =>
    array (
     
'vid' => '4',
     
'name' => 'Multimedia',
     
'description' => 'The kind of Video or other multimedia being added, such as Highlight or Tutorial.',
     
'help' => '',
     
'relations' => '1',
     
'hierarchy' => '1',
     
'multiple' => '0',
     
'required' => '1',
     
'tags' => '0',
     
'module' => 'taxonomy',
     
'weight' => '0',
     
'nodes' =>
      array (
       
'video' => 'video',
      ),
    ),
   
'name' =>
    array (
     
'#value' => 'Multimedia',
    ),
   
'types' =>
    array (
     
'#value' => 'Video',
    ),
   
'weight' =>
    array (
     
'#type' => 'weight',
     
'#delta' => 10,
     
'#default_value' => '0',
    ),
   
'edit' =>
    array (
     
'#value' => 'edit vocabulary',
    ),
   
'list' =>
    array (
     
'#value' => 'list terms',
    ),
   
'add' =>
    array (
     
'#value' => 'add terms',
    ),
  ),
 
5 =>
  array (
   
'#vocabulary' =>
    array (
     
'vid' => '5',
     
'name' => 'Platform',
     
'description' => 'The platform (Autodesk, Assimilate) on which a Product runs.',
     
'help' => '',
     
'relations' => '1',
     
'hierarchy' => '1',
     
'multiple' => '0',
     
'required' => '0',
     
'tags' => '0',
     
'module' => 'taxonomy',
     
'weight' => '0',
     
'nodes' =>
      array (
       
'product' => 'product',
      ),
    ),
   
'name' =>
    array (
     
'#value' => 'Platform',
    ),
   
'types' =>
    array (
     
'#value' => 'Product',
    ),
   
'weight' =>
    array (
     
'#type' => 'weight',
     
'#delta' => 10,
     
'#default_value' => '0',
    ),
   
'edit' =>
    array (
     
'#value' => 'edit vocabulary',
    ),
   
'list' =>
    array (
     
'#value' => 'list terms',
    ),
   
'add' =>
    array (
     
'#value' => 'add terms',
    ),
  ),
 
1 =>
  array (
   
'#vocabulary' =>
    array (
     
'vid' => '1',
     
'name' => 'Products',
     
'description' => 'GenArts products.',
     
'help' => 'Select applicable GenArts products.',
     
'relations' => '1',
     
'hierarchy' => '0',
     
'multiple' => '1',
     
'required' => '0',
     
'tags' => '0',
     
'module' => 'taxonomy',
     
'weight' => '0',
     
'nodes' =>
      array (
       
'story' => 'story',
       
'video' => 'video',
      ),
    ),
   
'name' =>
    array (
     
'#value' => 'Products',
    ),
   
'types' =>
    array (
     
'#value' => 'Customer story, Video',
    ),
   
'weight' =>
    array (
     
'#type' => 'weight',
     
'#delta' => 10,
     
'#default_value' => '0',
    ),
   
'edit' =>
    array (
     
'#value' => 'edit vocabulary',
    ),
   
'list' =>
    array (
     
'#value' => 'list terms',
    ),
   
'add' =>
    array (
     
'#value' => 'add terms',
    ),
  ),
 
'submit' =>
  array (
   
'#type' => 'submit',
   
'#value' => 'Save',
  ),
 
'#parameters' =>
  array (
   
0 => 'taxonomy_overview_vocabularies',
   
1 =>
    array (
     
'storage' => NULL,
     
'submitted' => false,
     
'post' =>
      array (
      ),
    ),
  ),
 
'#build_id' => 'form-62a0f09d87e03556fdf838b714cdcfc6',
 
'#type' => 'form',
 
'#programmed' => false,
 
'form_build_id' =>
  array (
   
'#type' => 'hidden',
   
'#value' => 'form-62a0f09d87e03556fdf838b714cdcfc6',
   
'#id' => 'form-62a0f09d87e03556fdf838b714cdcfc6',
   
'#name' => 'form_build_id',
  ),
 
'#token' => 'taxonomy_overview_vocabularies',
 
'form_token' =>
  array (
   
'#id' => 'edit-taxonomy-overview-vocabularies-form-token',
   
'#type' => 'token',
   
'#default_value' => '4cd2ac9457bb20e6f0af5fabe1c5eba5',
  ),
 
'form_id' =>
  array (
   
'#type' => 'hidden',
   
'#value' => 'taxonomy_overview_vocabularies',
   
'#id' => 'edit-taxonomy-overview-vocabularies',
  ),
 
'#id' => 'taxonomy-overview-vocabularies',
 
'#description' => NULL,
 
'#attributes' =>
  array (
  ),
 
'#required' => false,
 
'#parents' =>
  array (
  ),
 
'#method' => 'post',
 
'#action' => '/genarts/admin/content/taxonomy',
 
'#submit' =>
  array (
   
0 => 'taxonomy_overview_vocabularies_submit',
  ),
 
'#after_build' =>
  array (
   
0 => 'checkall_form_after_build',
  ),
)
?>

Comments

any luck with it ?

hi .
did u find a solution 'breaking' the vocs fieldset and rearrange the vocs fields where u wanted to ?

I also did something

I wrote my custom module for this.
http://ashish-thakur.blogspot.in/2012/06/taxonomy-add-edit-form-simplified-for.html
May be helpful here.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • 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> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.