<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

if ($element->isHelpTextHTML()) {
	$help = $element->getHelpText();
}
else {
	$help = nl2br(sly_translate($element->getHelpText(), true));
}

$char        = chr(97 + $column);
$outerClass  = array('sly-form-col-'.$char, $element->getOuterClass());
$help        = $element->getHelpText() ? '<span class="sly-form-helptext">'.$help.'</span>' : '';
$isContainer = $element->isContainer();
$label       = $element->getLabel();
$label       = empty($label) ? '&nbsp;' : sly_translate($label, true).':';
$label       = preg_replace('#\*\*(.*?)\*\*#i', '<strong>$1</strong>', $label);
$label       = preg_replace('#__(.*?)__#i', '<em>$1</em>', $label);
$label       = preg_replace('#//(.*?)//#i', '<em>$1</em>', $label);

// Elemente einrücken

if (preg_match('#^( *)#', $label, $matches)) {
	$label = preg_replace('#^( *)#', str_repeat('&nbsp;', strlen($matches[1])), $label);
}

if ($isContainer) {
	print $element->render();
}
else {
	?>
	<div class="<?php echo implode(' ', $outerClass) ?>">
		<label for="<?php echo $element->getID() ?>"><?php echo $label ?></label>
		<?php echo $element->render() ?>
		<?php echo $help ?>
	</div>
	<?php
}
