<?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
 */

$outerClass  = $element->getOuterClass();
$outerClass  = $outerClass ? ' class="'.$outerClass.'"' : '';
$help        = $element->getHelpText() ? '<span class="sly-form-helptext">'.nl2br(sly_translate($element->getHelpText(), true)).'</span>' : '';
$isContainer = $element->isContainer();
$label       = $element->getLabel();
$label       = empty($label) ? '&nbsp;' : sly_translate($label, true).':';

// 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="sly-form-row<?php echo $isLast ? ' last' : '' ?>">
		<p<?php echo $outerClass ?>>
			<label for="<?php echo $element->getID() ?>"><?php echo $label ?></label>
			<?php echo $element->render() ?>
			<?php echo $help ?>
		</p>
	</div>
	<?php
}
