You are here

function farm_term_parse_names in farmOS 7

Parse a string of term names and return an array of loaded term entities. If term names do not exist, they can optionally be created.

Parameters

string $names: A comma-separated list of term names.

bool $create: Whether or not to create terms that don't exist. Defaults to FALSE.

Return value

array Returns an array of term objects. If the term names exist, they will be loaded from the database. Otherwise, they will be created.

10 calls to farm_term_parse_names()
farm_area_parse_names in modules/farm/farm_area/farm_area.module
Parse a string of area names and return an array of loaded area entities. If area names do not exist, they can optionally be created.
farm_crop_planting_quick_form_submit in modules/farm/farm_crop/farm_crop.farm_quick.planting.inc
Planting quick form submit.
farm_livestock_move_form in modules/farm/farm_livestock/farm_livestock.farm_quick.move.inc
Form for adding animal movement logs.
farm_livestock_move_form_submit in modules/farm/farm_livestock/farm_livestock.farm_quick.move.inc
Submit function for movement quick form.
farm_movement_asset_location_submit in modules/farm/farm_movement/farm_movement.location.inc
Submit handler for processing the asset location field.

... See full list

File

modules/farm/farm_term/farm_term.module, line 73
Code for the Farm Term module.

Code

function farm_term_parse_names($names, $vocabulary, $create = FALSE) {

  // Start with an empty array.
  $terms = array();

  // Explode the value into an array and only take the first value.
  // (Same behavior as taxonomy autocomplete widget.)
  $values = drupal_explode_tags($names);

  // If the value is empty, bail.
  if (empty($values)) {
    return $terms;
  }

  // Iterate through the values and built an array of terms.
  foreach ($values as $value) {

    // Create/load the term.
    $term = farm_term($value, $vocabulary, $create);

    // Add to the array of terms.
    $terms[] = $term;
  }

  // Return the array of terms.
  return $terms;
}