You are here

public function SmartIpEventSubscriber::formSettings in Smart IP 8.2

Same name and namespace in other branches
  1. 8.4 modules/smart_ip_ipinfodb_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ipinfodb_web_service\EventSubscriber\SmartIpEventSubscriber::formSettings()
  2. 8.3 modules/smart_ip_ipinfodb_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ipinfodb_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:

Overrides SmartIpDataSourceInterface::formSettings

File

modules/smart_ip_ipinfodb_web_service/src/EventSubscriber/SmartIpEventSubscriber.php, line 97
Contains \Drupal\smart_ip_ipinfodb_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_ipinfodb_web_service\EventSubscriber

Code

public function formSettings(AdminSettingsEvent $event) {
  $config = \Drupal::config($this
    ->configName());
  $form = $event
    ->getForm();
  $form['smart_ip_data_source_selection']['smart_ip_data_source']['#options'][self::sourceId()] = t("Use @ipinfodb web service. The @ip2location free version database is used \n      by @ipinfodb in their web service. You will need an API key to use this \n      and you must be @login to get it. Note: if @ipinfodb respond too slow to \n      geolocation request, your site's performance will be affected specially if \n      Smart IP is configured to geolocate anonymous users.", array(
    '@ipinfodb' => Link::fromTextAndUrl(t('IPInfoDB.com'), Url::fromUri('http://www.ipinfodb.com'))
      ->toString(),
    '@ip2location' => Link::fromTextAndUrl(t('IP2Location'), Url::fromUri('http://www.ip2location.com'))
      ->toString(),
    '@login' => Link::fromTextAndUrl(t('logged in'), Url::fromUri('http://ipinfodb.com/login.php'))
      ->toString(),
  ));
  $form['smart_ip_data_source_selection']['ipinfodb_api_version'] = array(
    '#type' => 'select',
    '#title' => t('IPInfoDB API version'),
    '#default_value' => $config
      ->get('version'),
    '#options' => array(
      2 => 2,
      3 => 3,
    ),
    '#description' => t('IPInfoDB.com version 2 do have region code, in version 3 it was removed.'),
    '#states' => array(
      'visible' => array(
        ':input[name="smart_ip_data_source"]' => array(
          'value' => self::sourceId(),
        ),
      ),
    ),
  );
  $form['smart_ip_data_source_selection']['ipinfodb_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('IPInfoDB key'),
    '#description' => t('The use of IPInfoDB.com service requires API key. Registration for the
        new API key is free, sign up @here.', array(
      '@here' => Link::fromTextAndUrl(t('here'), Url::fromUri('http://www.ipinfodb.com/register.php'))
        ->toString(),
    )),
    '#default_value' => $config
      ->get('api_key'),
    '#states' => array(
      'visible' => array(
        ':input[name="smart_ip_data_source"]' => array(
          'value' => self::sourceId(),
        ),
      ),
    ),
  );
  $event
    ->setForm($form);
}