false, ]; protected function getInfo($field = null, $default = null) { return Qs_Array::get($this->info, $field, $default); } protected function _getInfo($name, $value = null, $attribs = null, $options = null, $listsep = null) { $info = parent::_getInfo($name, $value, $attribs, $options, $listsep); $info['telOptions'] = $this->telOptionsDefaults; foreach ($this->telOptions as $name) { if (array_key_exists($name, $info['attribs'])) { $info['telOptions'][$name] = $info['attribs'][$name]; unset($info['attribs'][$name]); } } $info['hidden'] = [ 'type' => 'hidden', 'id' => $info['id'], 'name' => $info['name'], 'value' => $info['value'], ]; $info['tel'] = array_merge($info['attribs'], [ 'type' => 'tel', 'id' => $this->addPrefix($info['id']), 'value' => $info['value'], ]); if (Qs_Array::get($info['tel'], 'disable')) { $info['tel']['disabled'] = 'disabled'; unset($info['tel']['disable']); } return $info; } protected function addPrefix($value) { $prefix = '_'; if (false !== ($pos = strrpos($value, '['))) { if ('[]' == substr($value, -2)) { return $prefix . $value; } $pos++; return substr($value, 0, $pos) . $prefix . substr($value, $pos); } elseif (false !== ($pos = strrpos($value, '-'))) { $pos++; return substr($value, 0, $pos) . $prefix . substr($value, $pos); } return $prefix . $value; } public function formInternationalTel($name, $value = null, $attribs = null) { $this->info = $this->_getInfo($name, $value, $attribs); /** @var Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); $doc->addCriticalStylesheet('css/thirdpart/intlTelInput.css'); $doc->addScript('js/intl-tel-number/utils.js'); $doc->addScript('js/intl-tel-number/intlTelInput.js'); $doc->addScript('js/lib/form/element/internationalTel.js'); $options = [ 'id' => $this->getInfo('hidden[id]'), 'telId' => $this->getInfo('tel[id]'), 'tel' => array_merge(['allowExtensions' => true], $this->getInfo('telOptions')), ]; $doc->addInitObject('lib.form.element.InternationalTel', [$options]); return Qs\Html::renderTag('input', $this->getInfo('hidden')) . Qs\Html::renderTag('input', $this->getInfo('tel')); } }