-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checkbox.php
32 lines (24 loc) · 1.43 KB
/
Checkbox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace CMF\Field;
class Checkbox extends Base {
/** inheritdoc */
public static function displayList($value, $edit_link, &$settings, &$model)
{
return ($value === true || $value === 1) ? 'yes' : 'no';
}
/** inheritdoc */
public static function displayForm($value, &$settings, $model)
{
$include_label = isset($settings['label']) ? $settings['label'] : true;
$errors = $model->getErrorsForField($settings['mapping']['fieldName']);
$has_errors = count($errors) > 0;
$input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array();
$off_input = \Form::hidden($settings['mapping']['fieldName'], '0');
$input = \Form::checkbox($settings['mapping']['fieldName'], '1', $value, $input_attributes);
$title = $settings['title'].($has_errors ? ' - '.$errors[0] : '');
$label = (!$include_label) ? $input : html_tag('label', array( 'class' => 'checkbox' ), $input.'<span class="item-label"> '.$title.'</span>');
$description = isset($settings['description']) ? '<span class="help-block">'.$settings['description'].'</span>' : '';
if (isset($settings['wrap']) && $settings['wrap'] === false) return $label;
return html_tag('div', array( 'class' => 'field-type-checkbox controls control-group'.($has_errors ? ' error' : '') ), $off_input.$label.$description).'<div class="clear"></div>';
}
}