Is it possible to have a null term in the list? We have a large database of pre-existing nodes that we want to apply a primary term to and make it required. However, if we enable this we run the risk that content administrators won't check the primary term field and it will automatically default to the first item in the vocabulary.

I see discussion of a null,
option in the issue queue, is there something in our configuration that is preventing this from being enabled? Is this a patch that would be useful?

Thanks,

- Greg

CommentFileSizeAuthor
#3 primary_term.module.blank_term.patch780 bytesgold

Comments

schnippy’s picture

Status: Active » Needs review

I figured out how to modify this through a form_alter hook:

function <my-module>_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == "<my-content-type>_node_form") {
        array_unshift($form["primaryterm"]["#options"], " -- Select a Term -- ");
  }

It correctly adds the 'null' option to the top of the list but the '#required' validation isn't working on this so if this field is marked as 'required' on the content-type admin screen but the editor leaves this option set to this new null value, it will still validate.

therzog’s picture

I second the motion for a null term. I my case, the vocabulary to which I'm applying primary term is optional. However, primary_term automatically sets the PT in the vocabulary, so even if I haven't selected anything, PT sets a term anyway, because there is no "not selected" option.

For now, thanks for the workaround, schnippy!

gold’s picture

StatusFileSize
new780 bytes

I just had to scratch this itch for a project I'm working on too.

The attached patch (svn diff) adds a blank --Select-- entry to the terms if the required flag is not set.

gold’s picture

Having just submitted this patch to add a blank option when a primary term is not required the client needed to have the blank option even when it is required to force the user to make a selection.

I've gone with schnippy's approach on this one though. The snippet above is almost right, missed the "taxonomy";

function <my-module>_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == "<my-content-type>_node_form") {
    array_unshift($form["taxonomy"]["primaryterm"]["#options"], " -- Select a Term -- ");
  }
}

The actual check I used though was the following;

if(isset($form['taxonomy']['primaryterm']['#options']) && $form['taxonomy']['primaryterm']['#required'])
daddison’s picture

If you're using the latest release for primary_term (6.x-1.2), then you need to leave out the 'taxonomy':

array_unshift($form['primaryterm']['#options'], ' -- Select a Term -- ');

Also, you might need to make sure that your custom module executes after the primary_term module. I used the util module to set the weight of my custom module to 10. The default weight of the primary_term module is 9.