Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm working on a block that will display a number of contacts in my organization. I'd like to make the set of people to display configurable. I'd like to provide the end user a list of positions from my taxonomy vocabulary called Positions. Each item would also need a textbox that would be the weight (where on the list the person would appear).

I thought I'd pull all the terms with taxonomy_get_tree in hook_block_configure, but I don't know how to make the form look the way I want. I want it in tabular format and on each row of the table: a checkbox indicating the position would be used in the block, the name of the taxonomy term and a textbox where the user can enter the weight.

On hook_block_save, I would go through the selected terms and weight values, create some string (most likely in json format) of the values and use set_variable to store the string, Is this possible? Is there a better way of doing this that I just don't know about.

Below is the relevant code of what I have so far

function contacts_blocks_block_configure($delta = '') {
  $form = array();
  //call a function to retrieve all positions
  $terms = _contacts_blocks_get_taxonomy_terms();
  switch($delta) {
    case "ClubContacts":
      //do something here with the terms
      break;

  }
  return $form;
}

function _contacts_blocks_get_taxonomy_terms() {
  //get the specific taxonomy, in this case one called positions
  $v = taxonomy_vocabulary_machine_name_load('positions');
  //load all the terms for the vocabulary
  $terms = taxonomy_get_tree($v->vid);
  //return the terms
  return $terms;
}

I'm not using views for this because my contacts content type allows someone to be assigned to more than one position, and I need to be able to group the contacts by a specific position, which I've come to find isn't possible using Views.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.