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_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_maxmind_geoip2_bin_db\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_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php, line 119
Contains \Drupal\smart_ip_maxmind_geoip2_bin_db\EventSubscriber\SmartIpEventSubscriber.

Class

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

Namespace

Drupal\smart_ip_maxmind_geoip2_bin_db\EventSubscriber

Code

public function formSettings(AdminSettingsEvent $event) {
  $config = \Drupal::config(self::configName());
  $autoUpdate = $config
    ->get('db_auto_update');
  $form = $event
    ->getForm();

  /** @var \Drupal\Core\File\FileSystem $filesystem */
  $filesystem = \Drupal::service('file_system');
  $privateFolder = $filesystem
    ->realpath(DatabaseFileUtilityBase::DRUPAL_FOLDER);
  $errorSourceId = \Drupal::state()
    ->get('smart_ip.request_db_error_source_id') ?: '';
  $autoDbUpdateLabel = t('Automatic MaxMind GeoIP2 binary database update');
  if (!$autoUpdate && $errorSourceId == self::sourceId()) {
    $form['smart_ip_bin_database_update']['#access'] = FALSE;
  }
  if (empty($privateFolder)) {
    $privateFolder = t('your "smart_ip" labelled folder inside your Drupal private folder (currently it is not yet set)');
  }
  else {
    $privateFolder = t('@path (default)', [
      '@path' => $privateFolder,
    ]);
  }
  $form['smart_ip_data_source_selection']['smart_ip_data_source']['#options'][self::sourceId()] = t("Use MaxMind GeoIP2 binary database. It is the evolution of MaxMind's \n      original GeoIP binary database or now called GeoIP Legacy. This MaxMind's \n      binary database uses a custom binary format to maximize lookup speed and \n      accessible via two available APIs: @maxmind_db_reader_api which includes \n      an optional C extension that you may @install to dramatically increase the \n      performance of lookups in GeoIP2 binary database and the default \n      @geoip2_api. The binary database file for both lite and licensed version \n      can be downloaded @here (you will need to @login to your MaxMind account \n      first). The binary database is roughly 130MB, and there's an option below \n      to enable the automatic download/extraction of it. If you prefer to \n      manually download the file %file_lite_city (if Lite version City edition) \n      or %file_licensed_city (if Licensed version City edition) or \n      %file_lite_country (if Lite version Country edition) or \n      %file_licensed_country (if Licensed version Country edition), it must be \n      uploaded to your server at @path or to your defined custom path (Note: It \n      is your responsibility to update them manually every month and to define \n      such a path, please set '@auto_update_label' to 'No', and fill in the \n      field which will then appear).", [
    '@maxmind_db_reader_api' => Link::fromTextAndUrl(t('MaxMind DB Reader PHP API'), Url::fromUri('https://github.com/maxmind/MaxMind-DB-Reader-php'))
      ->toString(),
    '@install' => Link::fromTextAndUrl(t('install'), Url::fromUri('https://www.webfoobar.com/node/71#install-maxmind-php-c-extension'))
      ->toString(),
    '@geoip2_api' => Link::fromTextAndUrl(t('GeoIP2 PHP API'), Url::fromUri('http://maxmind.github.io/GeoIP2-php'))
      ->toString(),
    '@login' => Link::fromTextAndUrl(t('login'), Url::fromUri('https://www.maxmind.com/en/account/login'))
      ->toString(),
    '@here' => Link::fromTextAndUrl(t('here'), Url::fromUri('https://www.maxmind.com/en/download_files'))
      ->toString(),
    '%file_lite_city' => MaxmindGeoip2BinDb::FILENAME_LITE_CITY . MaxmindGeoip2BinDb::FILE_EXTENSION,
    '%file_licensed_city' => MaxmindGeoip2BinDb::FILENAME_LINCENSED_CITY . MaxmindGeoip2BinDb::FILE_EXTENSION,
    '%file_lite_country' => MaxmindGeoip2BinDb::FILENAME_LITE_COUNTRY . MaxmindGeoip2BinDb::FILE_EXTENSION,
    '%file_licensed_country' => MaxmindGeoip2BinDb::FILENAME_LINCENSED_COUNTRY . MaxmindGeoip2BinDb::FILE_EXTENSION,
    '@path' => $privateFolder,
    '@auto_update_label' => $autoDbUpdateLabel,
  ]);
  $form['smart_ip_data_source_selection']['maxmind_geoip2_bin_db_version'] = [
    '#type' => 'select',
    '#title' => t('MaxMind GeoIP2 binary database version'),
    '#description' => t('Select version of MaxMind GeoIP2 binary database.'),
    '#options' => [
      MaxmindGeoip2BinDb::LINCENSED_VERSION => t('Licensed'),
      MaxmindGeoip2BinDb::LITE_VERSION => t('Lite'),
    ],
    '#default_value' => $config
      ->get('version'),
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_bin_db_edition'] = [
    '#type' => 'select',
    '#title' => t('MaxMind GeoIP2 binary database edition'),
    '#description' => t('Select edition of MaxMind GeoIP2 binary database.'),
    '#options' => [
      MaxmindGeoip2BinDb::CITY_EDITION => t('City'),
      MaxmindGeoip2BinDb::COUNTRY_EDITION => t('Country'),
    ],
    '#default_value' => $config
      ->get('edition'),
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_bin_db_user_account'] = [
    '#type' => 'textfield',
    '#title' => t('MaxMind user account ID'),
    '#description' => t('Enter your MaxMind user account ID. This is required for
        lite version.'),
    '#default_value' => $config
      ->get('user_account'),
    '#size' => 30,
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
        ':input[name="maxmind_geoip2_bin_db_version"]' => [
          'value' => MaxmindGeoip2BinDb::LITE_VERSION,
        ],
        ':input[name="maxmind_geoip2_bin_db_auto_update"]' => [
          'value' => '1',
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_bin_db_license_key'] = [
    '#type' => 'textfield',
    '#title' => t('MaxMind GeoIP2 license key'),
    '#description' => t("Enter your MaxMind GeoIP2 account's license key (view your \n        license key @here). This is required for lite and licensed version.", [
      '@here' => Link::fromTextAndUrl(t('here'), Url::fromUri('https://www.maxmind.com/en/my_license_key'))
        ->toString(),
    ]),
    '#default_value' => $config
      ->get('license_key'),
    '#size' => 30,
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
        ':input[name="maxmind_geoip2_bin_db_auto_update"]' => [
          'value' => '1',
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_bin_db_auto_update'] = [
    '#type' => 'select',
    '#title' => $autoDbUpdateLabel,
    '#description' => t('MaxMind GeoIP2 binary database will be automatically updated via
        cron.php every Wednesday (for licensed and lite/free versions).
        MaxMind GeoIP2 updates their database every Tuesday for licensed
        and free versions. @cron must be enabled for this to work.', [
      '@cron' => Link::fromTextAndUrl(t('Cron'), Url::fromRoute('system.cron_settings'))
        ->toString(),
    ]),
    '#options' => [
      TRUE => t('Yes'),
      FALSE => t('No'),
    ],
    '#default_value' => intval($autoUpdate),
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
      ],
    ],
  ];
  $form['smart_ip_data_source_selection']['maxmind_geoip2_bin_db_custom_path'] = [
    '#type' => 'textfield',
    '#title' => t('MaxMind GeoIP2 binary database custom path'),
    '#description' => t('Define the path where the MaxMind GeoIP2 binary database file is
        located in your server (Note: it is your responsibility to add security
        on this path. See the online handbook for @security). Include preceding
        slash but do not include trailing slash. This is useful for multi Drupal
        sites with each of their Smart IP module looks to a common MaxMind
        GeoIP2 binary database and it can be also useful for server with
        installed GeoIPLookup CLI tool where its MaxMind binary database file
        can be used here (usually its path is located at /usr/share/GeoIP). This
        path will be ignored if "Automatic MaxMind binary database update" is
        enabled which uses the Drupal private file system path. Leave it blank
        if you prefer the default Drupal private file system path.', [
      '@security' => Link::fromTextAndUrl(t('more information about securing private files'), Url::fromUri('https://www.drupal.org/documentation/modules/file'))
        ->toString(),
    ]),
    '#default_value' => $config
      ->get('bin_file_custom_path'),
    '#states' => [
      'visible' => [
        ':input[name="smart_ip_data_source"]' => [
          'value' => self::sourceId(),
        ],
        ':input[name="maxmind_geoip2_bin_db_auto_update"]' => [
          'value' => '0',
        ],
      ],
    ],
  ];
  $event
    ->setForm($form);
}