public function input($fieldName, array $options = [])
{
$options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => [], 'templateVars' => []];
$options = $this->_parseOptions($fieldName, $options);
$options += ['id' => $this->_domId($fieldName)];
$templater = $this->templater();
$newTemplates = $options['templates'];
if ($newTemplates) {
$templater->push();
$templateMethod = is_string($options['templates']) ? 'load' : 'add';
$templater->{$templateMethod}($options['templates']);
}
unset($options['templates']);
$error = null;
$errorSuffix = '';
if ($options['type'] !== 'hidden' && $options['error'] !== false) {
if (is_array($options['error'])) {
$error = $this->error($fieldName, $options['error'], $options['error']);
} else {
$error = $this->error($fieldName, $options['error']);
}
$errorSuffix = empty($error) ? '' : 'Error';
unset($options['error']);
}
$label = $options['label'];
unset($options['label']);
$nestedInput = false;
if ($options['type'] === 'checkbox') {
$nestedInput = true;
}
$nestedInput = isset($options['nestedInput']) ? $options['nestedInput'] : $nestedInput;
if ($nestedInput === true && $options['type'] === 'checkbox' && !array_key_exists('hiddenField', $options) && $label !== false) {
$options['hiddenField'] = '_split';
}
$input = $this->_getInput($fieldName, $options);
if ($options['type'] === 'hidden' || $options['type'] === 'submit') {
if ($newTemplates) {
$templater->pop();
}
return $input;
}
$label = $this->_getLabel($fieldName, compact('input', 'label', 'error', 'nestedInput') + $options);
$result = $this->_groupTemplate(compact('input', 'label', 'error', 'options'));
$result = $this->_inputContainerTemplate(['content' => $result, 'error' => $error, 'errorSuffix' => $errorSuffix, 'options' => $options]);
if ($newTemplates) {
$templater->pop();
}
return $result;
}