You are here

function location_taxonomize_initialize in Location Taxonomize 7

Same name and namespace in other branches
  1. 7.2 location_taxonomize.module \location_taxonomize_initialize()

Called from the configuration form. Handles initialization of Location Taxonomy

1 string reference to 'location_taxonomize_initialize'
location_taxonomize_form in ./location_taxonomize.admin.inc
Location Taxonomize administration form

File

./location_taxonomize.module, line 69

Code

function location_taxonomize_initialize($form, $form_state) {
  $values_init = $form_state['values']['location_taxonomize_vocab'];
  $method = $values_init['method'];
  switch ($method) {
    case 'new':

      // create a new location vocabulary
      taxonomy_vocabulary_save((object) array(
        'name' => t('Location'),
        'machine_name' => LOCATION_TAXONOMIZE_VOCAB_NAME,
        'description' => t('This vocabulary is synchronized with Location data automatically by the @name module', array(
          '@name' => LOCATION_TAXONOMIZE_MODULE_NAME,
        )),
      ));

      // save the vid of the newly created vocabulary
      $vocab = taxonomy_vocabulary_machine_name_load(LOCATION_TAXONOMIZE_VOCAB_NAME);
      $vid = $vocab->vid;
      variable_set('location_taxonomize_vid', $vid);
      $msg = t('Successfully created the Location taxonomy (vid @vid)', array(
        '@vid' => $vid,
      ));
      break;
    case 'existing':

      // save the vid of the existing vocabulary
      $vid = $values_init['possible_vid'];
      variable_set('location_taxonomize_vid', $vid);
      $msg = t('Successfully connected to the existing Location Vocabulary (vid @vid)', array(
        '@vid' => $vid,
      ));
      break;
  }
  drupal_set_message($msg);

  // Create the 'taxonomy_longname' field if it doesn't already exist.
  if (!field_info_field('location_taxonomize_longname')) {
    $field = array(
      'field_name' => 'location_taxonomize_longname',
      'type' => 'text',
    );
    field_create_field($field);
  }

  // Create the instance on the bundle.
  if (!field_info_instance('taxonomy_term', 'location_taxonomize_longname', 'location_taxonomize')) {
    $instance = array(
      'field_name' => 'location_taxonomize_longname',
      'label' => t('Long Name'),
      'entity_type' => 'taxonomy_term',
      'bundle' => 'location_taxonomize',
    );
    field_create_instance($instance);
  }

  // set defaults for longname fields
  _location_taxonomize_init_var_longname();
  drupal_set_message(t('Location Taxonomize initialized successfully'));
}