You are here

function biblio_contributor_widget in Bibliography Module 7.2

Same name and namespace in other branches
  1. 7 biblio.module \biblio_contributor_widget()

Get form structure for the multivalued add contributor widget

Parameters

object $biblio:

array $form_state:

Return value

array

1 call to biblio_contributor_widget()
biblio_form in ./biblio.module
Displays the Add/Edit form for a biblio entity

File

./biblio.module, line 1353

Code

function biblio_contributor_widget($biblio, &$form_state) {
  module_load_include('inc', 'biblio', 'includes/biblio.contributors');
  $categories = biblio_contributor_categories();
  $init_count = variable_get('biblio_init_auth_count', 4);
  $contributor_count = 0;

  // $biblio_wrapper = biblio_wrapper($biblio, 'biblio');
  $contributors = biblio_get_contributors($biblio);
  if (isset($form_state['biblio_imported_contributors'])) {

    // Reset the contributors array. If repopulating form, 4 blank
    // contributors show up from the previous form build.
    foreach ($form_state['biblio_imported_contributors'] as $author_data) {
      $contributors[] = $author_data;
    }
  }

  // Container for just the contributors.
  $wrapper = array();
  $wrapper['biblio_contributors'] = array(
    '#tree' => TRUE,
    '#weight' => 0,
    '#theme' => 'biblio_contributors',
    '#prefix' => '<div id="biblio-contributors-wrapper">',
    '#suffix' => '</div>',
  );
  foreach ($contributors as $cid => $info) {
    $wrapper['biblio_contributors'][] = array();
    end($wrapper['biblio_contributors']);
    $delta = key($wrapper['biblio_contributors']);
    $wrapper['biblio_contributors'][$delta] = biblio_contributor_biblio_form($info, $biblio, $form_state);
    $contributor_count++;
  }
  if (isset($form_state['biblio_contrib_count'])) {
    $form_count = max(max($init_count, $contributor_count), $form_state['biblio_contrib_count']);
  }
  else {
    $form_count = max($init_count, $contributor_count);
    $form_state['biblio_contrib_count'] = $form_count;
  }
  if ($form_count > $contributor_count) {
    $author = array();

    // array to hold the entity objects that will be generated for each contributor name field
    // (only those submitted with values will actually be saved)
    for ($i = 0; $i < $form_count - $contributor_count; $i++) {

      // Put the current contributor form in our main form
      $wrapper['biblio_contributors'][] = biblio_contributor_biblio_form(array(), $biblio, $form_state);
    }
  }
  $wrapper['add_more'] = array(
    '#type' => 'submit',
    '#value' => t('More contributors'),
    '#description' => t("If there aren't enough boxes above, click here to add more."),
    '#weight' => 0.1,
    '#submit' => array(
      'biblio_contributors_add_more',
    ),
    // If no javascript action.
    '#limit_validation_errors' => array(),
    '#ajax' => array(
      'callback' => 'biblio_contributors_add_more_callback',
      'wrapper' => 'biblio-contributors-wrapper',
    ),
  );
  return $wrapper;
}