/** * @param boolean $geoDefaults * @return \FieldList */ public function getAddressFields($geoDefaults = true) { $fields = new CompositeField(); $localityValue = $this->owner->Locality; $countryCode = $this->owner->CountryCode; $postalCodeValue = $this->owner->PostalCode; if ((!$localityValue || !$countryCode || !$postalCodeValue) && $geoDefaults) { $addressFromIp = Geocoder::geocodeIp(null, 'city', true); if ($addressFromIp) { if (!$localityValue) { $localityValue = (string) $addressFromIp->getLocality(); } if (!$countryCode) { $countryCode = (string) $addressFromIp->getCountryCode(); } if (!$postalCodeValue) { $postalCodeValue = (string) $addressFromIp->getPostalCode(); } } } $longWidth = 300; $shortWidth = 80; $streetname = new TextField('StreetName', _t('GeoMemberExtension.STREETNAME', 'Street Name'), $this->owner->StreetName); $streetname->setAttribute('placeholder', _t('GeoMemberExtension.STREETNAME', 'Street Name')); $streetname->setTitle(''); $streetname->setAttribute('style', 'width:' . $longWidth . 'px'); $streetnumber = new TextField('StreetNumber', _t('GeoMemberExtension.STREETNUMBER', 'Street Number'), $this->owner->StreetNumber); $streetnumber->setAttribute('placeholder', _t('GeoMemberExtension.STREETNUMBERPLACEHOLDER', 'N°')); $streetnumber->setTitle(''); $streetnumber->setAttribute('style', 'width:' . $shortWidth . 'px'); $fields->push($street = new FieldGroup($streetname, $streetnumber)); $street->setTitle(_t('GeoMemberExtension.STREET', 'Street')); $street->setFieldHolderTemplate('AddressFieldHolder'); $postalCodeClass = 'TextField'; if (class_exists('PostCodeField')) { $postalCodeClass = 'PostCodeField'; } $postcode = new $postalCodeClass('PostalCode', _t('GeoMemberExtension.POSTCODE', 'Postal Code'), $postalCodeValue); $postcode->setAttribute('placeholder', _t('GeoMemberExtension.POSTCODEPLACEHOLDER', 'Postcode')); $postcode->setTitle(''); $postcode->setAttribute('style', 'width:' . $shortWidth . 'px'); $locality = new TextField('Locality', _t('GeoMemberExtension.CITY', 'City'), $localityValue); $locality->setAttribute('placeholder', _t('GeoMemberExtension.CITY', 'City')); $locality->setTitle(''); $locality->setAttribute('style', 'width:' . $longWidth . 'px'); $fields->push($localitygroup = new FieldGroup($postcode, $locality)); $localitygroup->setTitle(_t('GeoMemberExtension.LOCALITY', 'Locality')); $localitygroup->setFieldHolderTemplate('AddressFieldHolder'); // Support some countries administrative areas if ($this->owner->CountryCode == 'FR') { $fields->push(new FrenchDepartmentField()); } if ($this->owner->CountryCode == 'BE') { $fields->push(new BelgianProvinceField()); } $label = _t('GeoMemberExtension.COUNTRY', 'Country'); $fields->push($countrydd = new CountryDropdownField('CountryCode', _t('GeoMemberExtension.COUNTRY', 'Country'), self::getCountryList(), $countryCode)); $countrydd->setEmptyString(''); return $fields; }