You are here

function farm_area_import_form_create_submit in farmOS 7

Area importer form submit.

1 string reference to 'farm_area_import_form_create_submit'
farm_area_import_form in modules/farm/farm_area/farm_area_import/farm_area_import.module
Area import form.

File

modules/farm/farm_area/farm_area_import/farm_area_import.module, line 239
Farm area import module.

Code

function farm_area_import_form_create_submit(&$form, &$form_state) {

  // If a parent area name was provided, load/create it and remember its ID.
  $parent_tid = 0;
  if (!empty($form_state['values']['output']['parent'])) {
    $parent_area = farm_term($form_state['values']['output']['parent'], 'farm_areas');
    if (!empty($parent_area->tid)) {
      $parent_tid = $parent_area->tid;
    }

    // Display a message with a link to the new area.
    $area_label = entity_label('taxonomy_term', $parent_area);
    $area_uri = entity_uri('taxonomy_term', $parent_area);
    drupal_set_message(t('Area created: <a href="@path">@label</a>', array(
      '@path' => url($area_uri['path']),
      '@label' => $area_label,
    )));
  }

  // Iterate through the submitted values.
  foreach ($form_state['values']['output'] as $values) {

    // If the confirmation checkbox is not checked, skip.
    if (empty($values['confirm'])) {
      continue;
    }

    // Create a new area term object.
    $area = farm_term($values['name'], 'farm_areas', TRUE, FALSE);

    // Set extra fields
    $area->description = $values['description'];
    $area->parent = $parent_tid;
    $area->field_farm_area_type[LANGUAGE_NONE][0]['value'] = $values['type'];
    $area->field_farm_geofield[LANGUAGE_NONE][0]['geom'] = $values['geometry'];

    // Save the area term.
    taxonomy_term_save($area);

    // Display a message with a link to the new area.
    $area_label = entity_label('taxonomy_term', $area);
    $area_uri = entity_uri('taxonomy_term', $area);
    drupal_set_message(t('Area created: <a href="@path">@label</a>', array(
      '@path' => url($area_uri['path']),
      '@label' => $area_label,
    )));
  }
}