/** * @param string $key * * @return Utils\Html * * @throws Exceptions\InvalidArgumentException */ public function getControlPart($key) { $name = $this->getHtmlName(); // Try to get translator $translator = $this->getTranslator(); if ($translator instanceof Localization\ITranslator && method_exists($translator, 'getLocale') === TRUE) { try { $locale = $translator->getLocale(); } catch (\Exception $ex) { $locale = 'en_US'; } } else { $locale = 'en_US'; } if ($key === static::FIELD_COUNTRY) { $control = Forms\Helpers::createSelectBox(array_reduce($this->getAllowedCountries(), function (array $result, $row) use($locale) { $countryName = FormPhone\Locale\Locale::getDisplayRegion(FormPhone\Locale\Locale::countryCodeToLocale($row), $locale); $result[$row] = Utils\Html::el('option')->setText('+' . $this->phoneUtils->getCountryCodeForCountry($row) . ' (' . $countryName . ')')->addAttributes(['data-mask' => preg_replace('/[0-9]/', '9', $this->phoneUtils->getExampleNationalNumber($row))])->value($row); return $result; }, []), ['selected?' => $this->country === NULL ? $this->defaultCountry : $this->country]); $control->addAttributes(['name' => $name . '[' . static::FIELD_COUNTRY . ']', 'id' => $this->getHtmlId() . '-' . static::FIELD_COUNTRY, 'data-ipub-forms-phone' => '', 'data-settings' => json_encode(['field' => $name . '[' . static::FIELD_NUMBER . ']'])]); if ($this->isDisabled()) { $control->disabled(TRUE); } return $control; } else { if ($key === static::FIELD_NUMBER) { $input = parent::getControl(); $control = Utils\Html::el('input'); $control->addAttributes(['name' => $name . '[' . static::FIELD_NUMBER . ']', 'id' => $this->getHtmlId() . '-' . static::FIELD_NUMBER, 'value' => $this->number, 'type' => 'text', 'data-nette-empty-value' => Utils\Strings::trim($this->translate($this->emptyValue)), 'data-nette-rules' => $input->{'data-nette-rules'}]); if ($this->isDisabled()) { $control->disabled(TRUE); } return $control; } } throw new Exceptions\InvalidArgumentException('Part ' . $key . ' does not exist.'); }