<?php $this->extend('form_row'); ?>

<?php $this->block('label'); ?>
  <?php if ($this->hasErrors()): ?>
    <span class="errortip" title="<?php echo htmlspecialchars($this->getErrorsAsString()); ?>" data-tooltip="position: top; offsetY: 10; theme: tooltipster-error; contentAsHTML: true;">?</span>
  <?php endif; ?>

  <?php if ($this->label): ?>
    <label for="ctrl_<?php echo $this->id; ?>"<?php if ($this->class): ?> class="<?php echo $this->class; ?>"<?php endif; ?>>
      <?php if ($this->mandatory): ?>
        <span class="invisible"><?php echo $this->mandatoryField; ?></span> <?php echo $this->label; ?><span class="mandatory">*</span>
      <?php else: ?>
        <?php echo $this->label; ?>
      <?php endif; ?>
    </label>
  <?php endif; ?>
<?php $this->endblock(); ?>

<?php $this->block('field'); ?>
  <select name="<?php echo $this->name; ?>" id="ctrl_<?php echo $this->id; ?>" class="<?php echo $this->class; ?>"<?php echo $this->getAttributes(); ?>>
    <?php foreach ($this->getOptions() as $option): ?>
      <?php if ($option['type'] == 'group_start'): ?>
        <optgroup label="<?php echo $option['label']; ?>">
      <?php endif; ?>

      <?php if ($option['type'] == 'option'): ?>
        <option value="<?php echo $option['value']; ?>"<?php echo $option['selected']; ?>><?php echo $option['label']; ?></option>
      <?php endif; ?>

      <?php if ($option['type'] == 'group_end'): ?>
        </optgroup>
      <?php endif; ?>
    <?php endforeach; ?>
  </select>
<?php $this->endblock(); ?>