Use farm_term_parse_names instead of introducing new farm_season_parse_names() function.

This commit is contained in:
Michael Stenta 2020-05-24 15:49:10 -04:00
parent 9214d72a24
commit 49612fd98b
2 changed files with 1 additions and 42 deletions

View File

@ -330,7 +330,7 @@ function farm_crop_planting_quick_form_submit($form, &$form_state) {
variable_set('farm_crop_planting_season', $season);
// Load/create the season term.
$seasons = farm_season_parse_names($season, TRUE);
$seasons = farm_term_parse_names($season, 'farm_season', TRUE);
// Get the crop(s) and load/create terms for each.
$crops = array();

View File

@ -19,44 +19,3 @@ function farm_season_farm_ui_entities() {
),
);
}
/**
* Parse a string of season names and return an array of loaded season entities. If
* season names do not exist, they can optionally be created.
*
* @param string $names
* A comma-separated list of season names.
* @param bool $create
* Whether or not to create seasons that don't exist. Defaults to FALSE.
*
* @return array
* Returns an array of season objects. If the season names exist, they will be
* loaded from the database. Otherwise, they will be created.
*/
function farm_season_parse_names($names, $create = FALSE) {
// Start with an empty array.
$seasons = 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 $seasons;
}
// Iterate through the values and build an array of seasons.
foreach ($values as $value) {
// Create/load the season term.
$season = farm_term($value, 'farm_season', $create);
// Add to the array of seasons.
$seasons[] = $season;
}
// Return the array of seasons.
return $seasons;
}