setTemplate('metro_select', 'geo'); $this->setKey('metro_select'); $this->setTitle(_t('geo', 'Metro')); } public function data() { if (! Geo::metroEnabled()) { return false; } $data = parent::data(); $data['stationId'] = $stationId = $this->stationId(); $data['cityId'] = $cityId = $this->cityId(); $data['visible'] = $this->visible(); $data['metro_data'] = []; if ($cityId) { $data['metro_data'] = Geo::cityMetro($cityId, ['selected' => $stationId]); if ($stationId && empty($data['metro_data']['sel']['id'])) { $data['stationId'] = 0; } } return $data; } public function stationId() { if (is_callable($this->stationId)) { return call_user_func($this->stationId); } return $this->stationId; } public function cityId() { if (is_callable($this->cityId)) { return call_user_func($this->cityId); } return $this->cityId; } public function visible() { return Geo::hasMetro($this->cityId()); } /** * Handle form reload block * @param $event string * @return string */ 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 rules(): array { $rules = []; $name = $this->fieldName; if (! empty($name)) { $rules[$name] = [TYPE_UINT]; } return $rules; } }