protected function WeatherDisplayForm::getFreeDisplayNumber in Weather 8
Same name and namespace in other branches
- 2.0.x src/Form/WeatherDisplayForm.php \Drupal\weather\Form\WeatherDisplayForm::getFreeDisplayNumber()
Finds first free display number for given display type.
1 call to WeatherDisplayForm::getFreeDisplayNumber()
- WeatherDisplayForm::save in src/
Form/ WeatherDisplayForm.php - Form submission handler for the 'save' action.
File
- src/
Form/ WeatherDisplayForm.php, line 326
Class
- WeatherDisplayForm
- Form controller for the weather_display entity edit forms.
Namespace
Drupal\weather\FormCode
protected function getFreeDisplayNumber(string $displayType) : int {
// User display ID is always equal UID.
if ($displayType == WeatherDisplayInterface::USER_TYPE) {
return $this
->currentUser()
->id();
}
// Find next number for system-wide display.
$used_numbers = Database::getConnection()
->select('weather_display', 'wd')
->fields('wd', [
'number',
])
->condition('type', $displayType)
->execute();
$free_number = 1;
foreach ($used_numbers as $row) {
if ($row->number > $free_number) {
break;
}
else {
$free_number++;
}
}
return $free_number;
}