Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 822857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:51:29+00:00 2026-05-15T02:51:29+00:00

I’m trying to set the default value for a Content Taxonomy field in a

  • 0

I’m trying to set the default value for a Content Taxonomy field in a hook_form_alter, but can’t pin down the necessary format. I’ve tried this and many variations:

foreach (element_children($form) as $child) {
// Set $default_value.

  if ($form[$child]['tids']) {
// This, for Content Taxonomy fields, isn't working:
    $form[$child]['tids']['#default_value'] = array('value' => $default_value);
    dsm($form[$child]['tids']['#default_value']);
  }
  else {
// This, for other fields, is working:
    $form[$child][0]['#default_value']['value'] = $default_value;
  }
}

Can anyone tell me what I’m missing?

Edit:
In response to Henrik Opel (thanks for getting involved), here is the print out of the relevant field of the form with my changes to the default fields commented out, showing the ‘#default_value’ field I’m trying to influence.

It also shows that the option widget I’m using is Hierarchical Select (could this be a factor?). In the dsm() in the code above, the changes to the default value are recognised, but they don’t get processed later on.

field_name_of_content_taxonomy_field (Array, 3 elements)
  #tree (Boolean) TRUE
  #weight (String, 1 characters ) 5
  tids (Array, 7 elements)
    #title (String, 10 characters ) Vocabulary_name
    #type (String, 19 characters ) hierarchical_select
    #weight (String, 1 characters ) 5
    #config (Array, 15 elements)
      // 15 elements here
    #required (String, 1 characters ) 0
    #description (String, 0 characters )
    #default_value (Array, 0 elements)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:51:30+00:00Added an answer on May 15, 2026 at 2:51 am

    Turns out the answer was in the documentation:
    http://drupal.org/node/319190

    I’ve renamed the question to make it clear where the problem was. This narrows the question to a rather specific use-case, but both Content Taxonomy and Hierarchical Select are useful and recommended modules for dealing with large taxonomies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.