User login

Prepopulating CMT's additions to the edit vocabulary form

The below is quite moot, but an interesting addition to "Ben's brain loses to itself in 14 rounds" series. I decided to keep community management information for each vocabulary separate, called with cmt_get_vocabulary(), and turn both it and the results of taxonomy_get_vocabulary() into arrays and array_merge() them.

Because the form gets all its information by calling taxonomy_get_vocabulary($vid), when editing an existing vocabulary the form would forget all about the Community Managed Taxonomy option. Very sad.

It would be neat if there were a way to hook into an arbitrary function, or if taxonomy_get_vocabulary had a hook like taxonomy_save_vocabulary's lovely line:

module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);

(That's for updating, rather than inserting a new one, which taxonomy_save_vocabulary also handles, in addition to deleting a vocabulary.)

That is entirely not the case, although it's at least making me think about how other modules might want to hook into CMT. No useful thoughts yet.

So what to do? Simply check if we're dealing with a pre-populated form (there may be another, standardized way to do this rather than the below) and go get the values from the database ourself if we are.

OK, actually I didn't need to do this (see below), but if I had it would have looked something like this:

/**
* Implementation of hook_form_alter().
*
* This will be a pretty important hook for CMT!
*  First, to add vocabularies to community management.
*/
function cmt_form_alter($form_id, &$form) {
  if ($form_id == 'taxonomy_form_vocabulary') {
    $cmt_vocabulary = array();
    if ($form['vid']) {
      $edit['cmt_vocabulary'] = cmt_get_vocabulary()
    }
$cmt_vocabulary['cmt_vocabulary'] = array(
  '#type' => 'radios',
      '#title' => t('Community-managed Vocabulary'),
      '#default_value' => $edit['cmt_vocabulary'],
       '#options' => array(t('Disabled'), t('No threshold'), t('Low threshold'), ),
      );
}
}

There is one way to store information that taxonomy_get_vocabulary will pull up so that other modules have it available: we can save the vocabulary->module property as cmt rather than taxonomy. If I were theming vocabularies I might like to know that. Are there other modules (tagadelic?) that will treat cmt vocabularies as second-class citizens if we don't leave them as taxonomy?

One thing about taxonomy_get_vocabulary that confused me was an apparently unnecessary order by clause, and I created the least important issue in Drupal history, "Unnecessary code in taxonomy_get_vocabulary()? "ORDER BY" on fields that will be identical for an entire result."

The below is quite moot, but an interesting addition to "Ben's brain loses to itself in 14 rounds" series. I decided to keep community management information for each vocabulary separate, called with cmt_get_vocabulary(), and turn both it and the results of taxonomy_get_vocabulary() into arrays and array_merge() them.

Because the form gets all its information by calling taxonomy_get_vocabulary($vid), when editing an existing vocabulary the form would forget all about the Community Managed Taxonomy option. Very sad.

It would be neat if there were a way to hook into an arbitrary function, or if taxonomy_get_vocabulary had a hook like taxonomy_save_vocabulary's lovely line:

module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);

(That's for updating, rather than inserting a new one, which taxonomy_save_vocabulary also handles, in addition to deleting a vocabulary.)

That is entirely not the case, although it's at least making me think about how other modules might want to hook into CMT. No useful thoughts yet.

So what to do? Simply check if we're dealing with a pre-populated form (there may be another, standardized way to do this rather than the below) and go get the values from the database ourself if we are.

OK, actually I didn't need to do this (see below), but if I had it would have looked something like this:

/**
* Implementation of hook_form_alter().
*
* This will be a pretty important hook for CMT!
*  First, to add vocabularies to community management.
*/
function cmt_form_alter($form_id, &$form) {
  if ($form_id == 'taxonomy_form_vocabulary') {
    $cmt_vocabulary = array();
    if ($form['vid']) {
      $edit['cmt_vocabulary'] = cmt_get_vocabulary()
    }
$cmt_vocabulary['cmt_vocabulary'] = array(
  '#type' => 'radios',
      '#title' => t('Community-managed Vocabulary'),
      '#default_value' => $edit['cmt_vocabulary'],
       '#options' => array(t('Disabled'), t('No threshold'), t('Low threshold'), ),
      );
}
}

There is one way to store information that taxonomy_get_vocabulary will pull up so that other modules have it available: we can save the vocabulary->module property as cmt rather than taxonomy. If I were theming vocabularies I might like to know that. Are there other modules (tagadelic?) that will treat cmt vocabularies as second-class citizens if we don't leave them as taxonomy?

One thing about taxonomy_get_vocabulary that confused me was an apparently unnecessary order by clause, and I created the least important issue in Drupal history, "Unnecessary code in taxonomy_get_vocabulary()? "ORDER BY" on fields that will be identical for an entire result."

Comments

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.