You are here

public function SmartIpEventSubscriber::formSettings in Smart IP 8.3

Same name in this branch
  1. 8.3 modules/device_geolocation/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\device_geolocation\EventSubscriber\SmartIpEventSubscriber::formSettings()
  2. 8.3 modules/smart_ip_maxmind_geoip2_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_maxmind_geoip2_bin_db\EventSubscriber\SmartIpEventSubscriber::formSettings()
  3. 8.3 modules/smart_ip_ipinfodb_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ipinfodb_web_service\EventSubscriber\SmartIpEventSubscriber::formSettings()
  4. 8.3 modules/smart_ip_ip2location_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber::formSettings()
  5. 8.3 modules/smart_ip_abstract_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_abstract_web_service\EventSubscriber\SmartIpEventSubscriber::formSettings()
  6. 8.3 modules/smart_ip_maxmind_geoip2_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_maxmind_geoip2_web_service\EventSubscriber\SmartIpEventSubscriber::formSettings()
Same name and namespace in other branches
  1. 8.4 modules/smart_ip_maxmind_geoip2_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_maxmind_geoip2_web_service\EventSubscriber\SmartIpEventSubscriber::formSettings()

Add the form elements of this Smart IP data source to main admin settings page of Smart IP.

Parameters

\Drupal\smart_ip\AdminSettingsEvent $event: Smart IP admin settings override event for event listeners.

Overrides SmartIpDataSourceInterface::formSettings

File

modules/smart_ip_maxmind_geoip2_web_service/src/EventSubscriber/SmartIpEventSubscriber.php, line 85
Contains \Drupal\smart_ip_maxmind_geoip2_web_service\EventSubscriber\SmartIpEventSubscriber.

Class

SmartIpEventSubscriber
Core functionalty of this Smart IP data source module. Listens to Smart IP override events.

Namespace

Drupal\smart_ip_maxmind_geoip2_web_service\EventSubscriber

Code

public function formSettings(AdminSettingsEvent $event) {
  $config = \Drupal::config(self::configName());
  $form = $event
    ->getForm();
  $form['smart_ip_data_source_selection']['smart_ip_data_source']['#options'][self::sourceId()] = t("Use @maxmind web service. A user ID and license key is required here. You \n      will need to @buy one of their services and they will provide you the \n      login details. You can view your user ID and license key inside your \n      @account.", [
    '@maxmind' => Link::fromTextAndUrl(t('MaxMind GeoIP2 Precision'), Url::fromUri('http://dev.maxmind.com/geoip/geoip2/web-services'))
      ->toString(),
    '@buy' => Link::fromTextAndUrl(t('buy'), Url::fromUri('https://www.maxmind.com/en/geoip2-precision-services'))
      ->toString(),
    '@account' => Link::fromTextAndUrl(t('MaxMind account'), Url::fromUri('https://www.maxmind.com/en/my_license_key'))
      ->toString(),
  ]);
  $form['smart_ip_data_source_selection']['maxmind_geoip2_web_service_type'] = [
    '#type' => 'select',
    '#title' => t('MaxMind GeoIP2 Precision Web Services'),
    '#description' => t('Choose type of service.'),
    '#options' => [
      MaxmindGeoip2WebService::COUNTRY_SERVICE => t('Country'),
      MaxmindGeoip2WebService::CITY_SERVICE => t('City'),
      MaxmindGeoip2WebService::INSIGHTS_SERVICE => t('Insights'),
    ],
    '#default_value' => $config
      ->get('service_type'),
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_web_service_uid'] = [
    '#type' => 'textfield',
    '#title' => t('MaxMind GeoIP2 Precision user ID'),
    '#description' => t("Enter your MaxMind GeoIP2 Precision account's user ID (view your user \n        ID @here).", [
      '@here' => Link::fromTextAndUrl(t('here'), Url::fromUri('https://www.maxmind.com/en/my_license_key'))
        ->toString(),
    ]),
    '#default_value' => $config
      ->get('user_id'),
    '#size' => 30,
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_web_service_license_key'] = [
    '#type' => 'textfield',
    '#title' => t('MaxMind GeoIP2 Precision license key'),
    '#default_value' => $config
      ->get('license_key'),
    '#description' => t("Enter your MaxMind GeoIP2 Precision account's license key (view your \n        license key @here).", [
      '@here' => Link::fromTextAndUrl(t('here'), Url::fromUri('https://www.maxmind.com/en/my_license_key'))
        ->toString(),
    ]),
    '#size' => 30,
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
      ],
    ],
  ];
  $event
    ->setForm($form);
}