You are here

public function Location::getSettingsForm in Geolocation Field 8.3

Same name in this branch
  1. 8.3 src/Plugin/geolocation/MapCenter/Location.php \Drupal\geolocation\Plugin\geolocation\MapCenter\Location::getSettingsForm()
  2. 8.3 src/Plugin/geolocation/LocationInput/Location.php \Drupal\geolocation\Plugin\geolocation\LocationInput\Location::getSettingsForm()
Same name and namespace in other branches
  1. 8.2 src/Plugin/geolocation/MapCenter/Location.php \Drupal\geolocation\Plugin\geolocation\MapCenter\Location::getSettingsForm()

Settings form by ID and context.

Parameters

int $center_option_id: MapCenter option ID.

array $settings: The current option settings.

mixed $context: Current context.

Return value

array A form array to be integrated in whatever.

Overrides MapCenterBase::getSettingsForm

File

src/Plugin/geolocation/MapCenter/Location.php, line 60

Class

Location
Location based map center.

Namespace

Drupal\geolocation\Plugin\geolocation\MapCenter

Code

public function getSettingsForm($location_plugin_id = NULL, array $settings = [], $context = NULL) {
  if (!$this->locationManager
    ->hasDefinition($location_plugin_id)) {
    return [];
  }
  $form = [];

  /** @var \Drupal\geolocation\LocationInterface $location_plugin */
  $location_plugin = $this->locationManager
    ->createInstance($location_plugin_id);
  $location_options = $location_plugin
    ->getAvailableLocationOptions($context);
  if (!$location_options) {
    return [];
  }
  $option_id = NULL;
  if (!empty($settings['location_option_id'])) {
    $settings['location_option_id'];
    $option_id = $settings['location_option_id'];
  }
  if (count($location_options) == 1) {
    $option_id = key($location_options);
    $form['location_option_id'] = [
      '#type' => 'value',
      '#value' => $option_id,
    ];
  }
  else {
    $options = [];
    foreach ($location_options as $location_option_id => $location_option_definition) {
      $options[$location_option_id] = $location_option_definition['name'];
    }
    $form['location_option_id'] = [
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => $option_id,
    ];
  }

  /** @var \Drupal\geolocation\LocationInterface $location_plugin */
  $location_plugin = $this->locationManager
    ->createInstance($location_plugin_id);
  $form = array_merge_recursive($form, $location_plugin
    ->getSettingsForm($option_id, $settings, $context));
  return $form;
}