| 1 |
<?php defined('ABSPATH') or die; |
| 2 |
/* @var PixCustomifyFormField $field */ |
| 3 |
/* @var PixCustomifyForm $form */ |
| 4 |
/* @var mixed $default */ |
| 5 |
/* @var string $name */ |
| 6 |
/* @var string $idname */ |
| 7 |
/* @var string $label */ |
| 8 |
/* @var string $desc */ |
| 9 |
/* @var string $rendering */ |
| 10 |
|
| 11 |
// [!!] a switch is a checkbox that is only ever either on or off; not to |
| 12 |
// be confused with a fully functional checkbox which may be many values |
| 13 |
|
| 14 |
$checked = $form->autovalue($name, $default); |
| 15 |
|
| 16 |
$attrs = array |
| 17 |
( |
| 18 |
'name' => $name, |
| 19 |
'type' => 'checkbox', |
| 20 |
'id' => $idname, |
| 21 |
'value' => 1, |
| 22 |
); |
| 23 |
|
| 24 |
// is the checkbox checked? |
| 25 |
if ($checked) { |
| 26 |
$attrs['checked'] = 'checked'; |
| 27 |
} |
| 28 |
|
| 29 |
// Label Fillins |
| 30 |
// ------------- |
| 31 |
|
| 32 |
if ($field->hasmeta('label-fillins')) { |
| 33 |
$fillers = array(); |
| 34 |
foreach ($field->getmeta('label-fillins', array()) as $fieldname => $conf) { |
| 35 |
$fillers[":$fieldname"] = $form->field($fieldname, $conf)->render(); |
| 36 |
} |
| 37 |
|
| 38 |
$processed_label = strtr($label, $fillers); |
| 39 |
} |
| 40 |
else { // no fillins available |
| 41 |
$processed_label = $label; |
| 42 |
} |
| 43 |
|
| 44 |
// group show |
| 45 |
|
| 46 |
if ($field->hasmeta('show_group')) { |
| 47 |
$attrs['data-show_group'] = $field->getmeta('show_group'); |
| 48 |
} |
| 49 |
?> |
| 50 |
|
| 51 |
<?php if ($rendering == 'inline'): ?> |
| 52 |
<input <?php echo $field->htmlattributes($attrs) ?> /> |
| 53 |
|
| 54 |
<?php elseif ($rendering == 'blocks'): ?> |
| 55 |
<div class="switch"> |
| 56 |
<input <?php echo $field->htmlattributes($attrs) ?> /> |
| 57 |
<label for="<?php echo $idname ?>"><?php echo $processed_label ?></label> |
| 58 |
</div> |
| 59 |
<?php else: # rendering != 'inline' ?> |
| 60 |
<label for="<?php echo $idname ?>"> |
| 61 |
<input <?php echo $field->htmlattributes($attrs) ?> /> |
| 62 |
<?php echo $processed_label ?> |
| 63 |
</label> |
| 64 |
<?php endif; ?> |
| 65 |
|