public function formatElement()
{
$s = '';
$values = explode('|', trim($this->getValue(), '|'));
$options = $this->getOptions();
$name = $this->getAttribute('name');
$id = $this->getAttribute('id');
$attr = '';
foreach ($this->getAttributes() as $attributeName => $attributeValue) {
if ($attributeName == 'name' || $attributeName == 'id') {
continue;
}
$attr .= ' ' . htmlspecialchars($attributeName) . '="' . htmlspecialchars($attributeValue) . '"';
}
$formElements = [];
foreach ($options as $opt_name => $opt_value) {
$opt_id = $id;
if ($opt_value != '') {
$opt_id .= '-' . rex_string::normalize($opt_value, '-');
}
$opt_attr = $attr . ' id="' . htmlspecialchars($opt_id) . '"';
$checked = in_array($opt_value, $values) ? ' checked="checked"' : '';
$n = [];
$n['label'] = '<label class="control-label" for="' . htmlspecialchars($opt_id) . '">' . htmlspecialchars($opt_name) . '</label>';
$n['field'] = '<input type="checkbox" name="' . htmlspecialchars($name) . '[' . htmlspecialchars($opt_value) . ']" value="' . htmlspecialchars($opt_value) . '"' . $opt_attr . $checked . ' />';
$formElements[] = $n;
}
$fragment = new rex_fragment();
$fragment->setVar('elements', $formElements, false);
$fragment->setVar('grouped', true);
$s = $fragment->parse('core/form/checkbox.php');
return $s;
}