setTemplate('addr_input', 'geo'); $this->setKey('addr_input'); $this->setTitle(_t('geo', 'Address of the Object')); } public function data() { $data = parent::data(); $data['visible'] = $this->visible(); $data['cityId'] = $cityId = $this->cityId(); $data['addr'] = $this->addr(); $data['lat'] = $this->lat(); $data['lon'] = $this->lon(); $data['city'] = $cityId ? Geo::regionData($cityId) : []; $data['attrAddr'] = $this->attrAddr(); return $data; } public function attrAddr() { HTML::attributeAddNotExist($this->attr, 'name', $this->fieldName); HTML::attributeAddNotExist($this->attr, 'type', 'text'); HTML::attributeAddNotExist($this->attr, 'value', $this->addr()); HTML::attributeAddNotExist($this->attr, 'placeholder', $this->placeholder ?? _t('geo', 'Specify the street, area, house number, etc.')); HTML::attributeAdd($this->attr, 'class', 'j-geo-map-addr-input-addr'); return $this->attr; } public function visible() { return $this->cityId() > 0; } public function reloadBlock($event) { if (is_callable($this->onReloadBlock)) { return call_user_func($this->onReloadBlock, $event); } if ($this->visible()) { return $this->render(); } return ''; } public function cityId() { if (is_callable($this->cityId)) { return call_user_func($this->cityId); } return $this->cityId; } public function addr() { if (! is_string($this->addr) && is_callable($this->addr)) { return call_user_func($this->addr); } return $this->addr; } public function lat() { if (! is_string($this->lat) && is_callable($this->lat)) { return call_user_func($this->lat); } return $this->lat; } public function lon() { if (! is_string($this->lon) && is_callable($this->lon)) { return call_user_func($this->lon); } return $this->lon; } public function rules(): array { $rules = []; $name = $this->fieldName; if (! empty($name)) { $rules[$name] = [TYPE_STR]; } $name = $this->fieldNameLat; if (! empty($name)) { $rules[$name] = [TYPE_STR]; } $name = $this->fieldNameLon; if (! empty($name)) { $rules[$name] = [TYPE_STR]; } return $rules; } }