protected function WeatherDisplayPlaceForm::getLocationSettings in Weather 8
Same name and namespace in other branches
- 2.0.x src/Form/WeatherDisplayPlaceForm.php \Drupal\weather\Form\WeatherDisplayPlaceForm::getLocationSettings()
Finds location settings for display Place form.
Parameters
\Drupal\weather\Entity\WeatherDisplayPlaceInterface|null $weather_display_place: Weather display place entity.
Return value
array Settings.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to WeatherDisplayPlaceForm::getLocationSettings()
- WeatherDisplayPlaceForm::buildForm in src/
Form/ WeatherDisplayPlaceForm.php - Form constructor.
File
- src/
Form/ WeatherDisplayPlaceForm.php, line 227
Class
- WeatherDisplayPlaceForm
- Form controller for the weather_display_place entity edit forms.
Namespace
Drupal\weather\FormCode
protected function getLocationSettings(WeatherDisplayPlaceInterface $weather_display_place = NULL) {
// Set defaults.
$settings = [
'geoid' => 'geonames_703448',
'displayed_name' => 'Kyiv',
'weight' => 0,
'country' => 'Ukraine',
];
if ($weather_display_place instanceof WeatherDisplayPlaceInterface) {
foreach ($settings as $field_name => $value) {
if ($weather_display_place
->hasField($field_name)) {
if ($weather_display_place
->get($field_name)
->getFieldDefinition()
->getType() == 'entity_reference') {
$settings[$field_name] = $weather_display_place->{$field_name}->target_id;
}
else {
$settings[$field_name] = $weather_display_place->{$field_name}->value;
}
}
}
// Find related country.
$place = $this->entityTypeManager
->getStorage('weather_place')
->load($settings['geoid']);
$settings['country'] = $place->country->value;
}
return $settings;
}