/**
  * Render an element
  * @param object $element
  * @return string
  */
 protected function element($element)
 {
     // set id
     if (!isset($element->attributes['id'])) {
         $element->id = $this->id();
         $attributes = $element->attributes;
         $attributes['id'] = $element->id;
         $element->attributes = $attributes;
     } else {
         $element->id = $element->attributes['id'];
     }
     // set class
     if (!isset($element->attributes['class'])) {
         // set bootstap class
         $attributes['class'] = '';
     }
     // set label
     if (!$element->label) {
         if ($element->text) {
             $element->label = $this->_text->get($element->text);
         } else {
             $element->label = $this->_text->get('label.' . $element->key);
         }
     }
     // set error
     if ($error = $element->error()) {
         // create  errormessage
         $element->error = $this->_text->get('error.' . $element->key . '.' . $error);
     } else {
         $element->error = FALSE;
     }
     // set comment
     if (!isset($element->comment)) {
         if ($comment = $this->_text->get('comment.' . $element->key)) {
             $element->comment = $comment;
         } else {
             $element->comment = FALSE;
         }
     }
     // set default view
     $view = 'form/element';
     // render the element itself
     switch ($element->type) {
         case 'radio':
         case 'checkbox':
         case 'select':
             if (Arr::is_assoc($element->options) === FALSE) {
                 $options = array();
                 foreach ($element->options as $value => $label) {
                     $value = $label;
                     $label = $this->_text->get('option.' . $element->key . '.' . $value);
                     $options[$value] = $label;
                 }
                 $element->options = $options;
             }
             if ($element->type === 'radio') {
                 $view = 'form/radio';
             }
             if ($element->type === 'checkbox') {
                 $view = 'form/checkbox';
             }
             if ($element->type === 'select') {
                 if (isset($element->first_option)) {
                     $option = $element->first_option;
                     $value = is_array($option) && isset($option['value']) ? $option['value'] : $option;
                     $label = is_array($option) && isset($option['label']) ? $option['label'] : $this->_text->get('option.' . $element->key . '.' . $value);
                     // add to the beginning of options
                     $reverse = array_reverse($element->options, TRUE);
                     $reverse[$value] = $label;
                     $element->options = array_reverse($reverse, TRUE);
                 }
                 // set bootstap class
                 $attributes['class'] .= ' form-control';
                 $element->html = FormHTML::select($element->name, $element->options, $element->value, $attributes);
             }
             break;
         case 'hidden':
             $view = FALSE;
             $element->html = FormHTML::hidden($element->name, $element->value, $attributes);
             break;
         case 'submit':
             $view = FALSE;
             $label = isset($element->label) ? $element->label : $this->_text->get('label.' . $element->key);
             $element->html = FormHTML::submit($element->name, $label, $attributes);
             break;
         case 'btn':
             $view = FALSE;
             $label = isset($element->label) ? $element->label : $this->_text->get('label.' . $element->key);
             $href = isset($element->href) ? $element->href : '#';
             $element->html = HTML::anchor($href, $label, $attributes);
             break;
         case 'button':
             $view = FALSE;
             $label = isset($element->label) ? $element->label : $this->_text->get('label.' . $element->key);
             $element->html = FormHTML::button($element->name, $label, $attributes);
             break;
         case 'file':
             $element->html = FormHTML::file($element->name, $attributes);
             break;
         case 'image':
             $element->html = FormHTML::image($element->name, $element->value, $attributes, FALSE);
             break;
         case 'text':
         case 'password':
             if (!isset($attributes['placeholder'])) {
                 $attributes['placeholder'] = $this->_text->get('placeholder.' . $element->key);
             }
             // set bootstap class
             $attributes['class'] .= ' form-control';
             if ($element->type === 'text') {
                 $element->html = FormHTML::input($element->name, $element->value, $attributes);
             }
             if ($element->type === 'password') {
                 $element->html = FormHTML::password($element->name, $element->value, $attributes);
             }
             break;
         case 'textarea':
             $attributes['class'] .= ' form-control';
             $element->html = FormHTML::textarea($element->name, $element->value, $attributes, FALSE);
             break;
         default:
             $element->html = View::factory('form/' . $element->type, array('viewer' => $this, 'element' => $element))->render();
     }
     // wrap element
     if ($view) {
         $html = View::factory($view, array('element' => $element))->render();
     } else {
         $html = $element->html;
     }
     return $html;
 }
<div class="yf" data-use="backend.form.Link" data-settings='<?php 
echo json_encode(array('url_create' => URL::to('Link@create', array('viewport' => 'item', 'callback' => '{{callback}}')), 'url_update' => URL::to('Link@update:{{id}}', array('viewport' => 'item', 'callback' => '{{callback}}')), 'url_delete' => URL::to('Link@delete:{{id}}'), 'url_json' => URL::to('Link@json:{{id}}')));
?>
'>
	
	<script class="yf-template" type="text/html">
		<div>
			<span>{{title}</span><br />
			<span>{{url}}</span>
		</div>
	</script>

	<?php 
echo FormHTML::hidden($element->name, $element->value, array('class' => 'yf-value'));
?>

	<div class="section">
		<?php 
echo HTML::anchor('#', text('label.link_create'), array('class' => 'yf-create btn btn-default btn-md', 'title' => text('label.link_create')));
?>
		<div class="pull-right">
			<?php 
echo HTML::anchor('#', '<span class="glyphicon glyphicon-pencil"></span>', array('class' => 'yf-update btn btn-default btn-xs', 'title' => text('label.link_update')));
echo HTML::anchor('#', '<span class="glyphicon glyphicon-trash"></span>', array('class' => 'yf-delete  btn btn-default btn-xs', 'title' => text('label.link_delete'), 'data-question' => text('question.link_delete')));
?>
		</div>
		<div class="yf-preview"></div>
	</div>
</div>
<div class="imageEmbed">

	<script class="imageEmbeddedTemplate" type="text/x-jquery-tmpl">
		<img src=<?php 
echo $_path['files'] . 'images/admin/';
?>
${file} width="90" height="90" />
	</script>
	
	<?php 
echo FormHTML::hidden($element->name . '[id]', $element->value['id'], array('class' => 'imageId'));
?>
	<?php 
echo FormHTML::hidden($element->name . '[file]', $element->value['file'], array('class' => 'imageFile'));
?>
	<?php 
echo FormHTML::hidden($element->name . '[title]', $element->value['title'], array('class' => 'imageTitle'));
?>
	
	<div class="imageEmbedded">
	</div>
	
		<?php 
echo HTML::anchor(Route::url($_route, array('mode' => 'browse', 'task' => 'select', 'controller' => $element->controller)), '<span>' . text($element->controller . ':label.browse') . '</span>', array('class' => 'browse btn'));
?>
</div>

<script type="text/javascript">yf.library('form.image.internal');</script>
<div class="yf  form-inline" data-use="backend.form.Item" data-settings='<?php 
echo json_encode(array('url_create' => URL::to('{{module}}@list', array('viewport' => 'module', 'task' => 'select', 'callback' => '{{callback}}')), 'url_update' => URL::to('{{module}}@list:{{id}}', array('viewport' => 'module', 'task' => 'select', 'callback' => '{{callback}}')), 'url_json' => URL::to('{{module}}@json:{{id}}')));
?>
'>
	
	<?php 
echo FormHTML::hidden($element->name . '[item_id]', $element->value['item_id'], array('class' => 'yf-item_id'));
?>
	
	<?php 
echo FormHTML::hidden($element->name . '[params]', isset($element->value['params']) && !empty($element->value['params']) ? json_encode($element->value['params']) : '{}', array('class' => 'yf-params'));
?>
	
	<?php 
echo FormHTML::hidden($element->name . '[request]', $element->value['request'], array('class' => 'yf-request'));
?>
	
	<div class="section">
		<div class="form-group">
			<select class="yf-item-module form-control" name="<?php 
echo $element->name . '[module]';
?>
">
				<?php 
foreach ($element->modules as $value => $label) {
    ?>
					<option value="<?php 
    echo $value;
    ?>
" <?php 
    echo $element->value['module'] == $value && $element->value['request'] == '' ? 'selected' : '';
	<!-- backup: when js fails, the original values will not be lost -->
	<!-- hidden will be removed directly when js loads -->
	<?php 
foreach ($values as $value) {
    ?>
		<?php 
    echo FormHTML::hidden($element->name, $value, array('class' => 'yf-value-backup'));
    ?>
	<?php 
}
?>
	
	<!-- value template -->
	<script class="yf-template-backup" type="text/html">
		<?php 
echo FormHTML::hidden($element->name, '{{value}}', array('class' => 'yf-value-backup'));
?>
	</script>
	
	<!-- item template -->
	<script class="yf-template" type="text/html">
		<div class="yf-item item">
			<input type="hidden" name="<?php 
echo $element->name;
?>
" value='{{id}}' />
			<div class="pull-right">
				<a href="#" class="yf-update btn btn-default btn-xs" title="<?php 
echo text('label.update') . ' ' . text($element->controller . ':module.single', array(), FALSE);
?>
"><span class="glyphicon glyphicon-pencil"></span></a>