Merge pull request #16008 from civicrm/5.20
[civicrm-core.git] / CRM / Admin / Form / Setting / Mapping.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for Mapping and Geocoding.
20 */
21 class CRM_Admin_Form_Setting_Mapping extends CRM_Admin_Form_Setting {
22
23 protected $_settings = [
24 'mapAPIKey' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
25 'mapProvider' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
26 'geoAPIKey' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
27 'geoProvider' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
28 ];
29
30 /**
31 * Build the form object.
32 */
33 public function buildQuickForm() {
34 CRM_Utils_System::setTitle(ts('Settings - Mapping and Geocoding Providers'));
35 parent::buildQuickForm();
36 }
37
38 /**
39 * Global form rule.
40 *
41 * @param array $fields
42 * The input form values.
43 *
44 * @return bool|array
45 * true if no errors, else array of errors
46 */
47 public static function formRule($fields) {
48 $errors = [];
49
50 if (!CRM_Utils_System::checkPHPVersion(5, FALSE)) {
51 $errors['_qf_default'] = ts('Mapping features require PHP version 5 or greater');
52 }
53
54 if ($fields['mapProvider'] == 'OpenStreetMaps' && $fields['geoProvider'] == '') {
55 $errors['geoProvider'] = "Please select a Geocoding Provider - Open Street Maps does not provide geocoding.";
56 }
57
58 return $errors;
59 }
60
61 /**
62 * Add the rules (mainly global rules) for form.
63 *
64 * All local rules are added near the element
65 */
66 public function addRules() {
67 $this->addFormRule(['CRM_Admin_Form_Setting_Mapping', 'formRule']);
68 }
69
70 }