| 1 |
<?php |
| 2 |
/** |
| 3 |
* The file contains a form layout based on Twitter Bootstrap 3 |
| 4 |
* |
| 5 |
* @author Alex Kovalev <[email protected]> |
| 6 |
* @copyright (c) 2018, Webcraftic Ltd |
| 7 |
* |
| 8 |
* @package factory-forms |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
if( !defined('ABSPATH') ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if( !class_exists('Wbcr_FactoryForms480_Bootstrap3FormLayout') ) { |
| 18 |
/** |
| 19 |
* A form layout based on Twitter Bootstrap 3 |
| 20 |
*/ |
| 21 |
class Wbcr_FactoryForms480_Bootstrap3FormLayout extends Wbcr_FactoryForms480_FormLayout { |
| 22 |
|
| 23 |
public $name = 'default'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Creates a new instance of a bootstrap3 form layout. |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
* @param array $options A holder options. |
| 30 |
* @param Wbcr_FactoryForms480_Form $form A parent form. |
| 31 |
*/ |
| 32 |
public function __construct($options, $form) |
| 33 |
{ |
| 34 |
parent::__construct($options, $form); |
| 35 |
|
| 36 |
$this->addCssClass('factory-bootstrap'); |
| 37 |
if( isset($options['cssClass']) ) { |
| 38 |
$this->addCssClass($options['cssClass']); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Renders a beginning of a form. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function beforeRendering() |
| 49 |
{ |
| 50 |
?> |
| 51 |
<div <?php $this->attrs() ?>> |
| 52 |
<div class="form-horizontal"> |
| 53 |
<?php |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Renders the end of a form. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* @return void |
| 61 |
*/ |
| 62 |
public function afterRendering() |
| 63 |
{ |
| 64 |
?> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
<?php |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* @param Wbcr_FactoryForms480_Control $control |
| 72 |
*/ |
| 73 |
public function beforeControl($control) |
| 74 |
{ |
| 75 |
if( $control->getType() == 'hidden' ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
$theme_class = ''; |
| 80 |
if( isset($control->options['theme']) ) { |
| 81 |
$theme_class = $control->options['theme']; |
| 82 |
} |
| 83 |
|
| 84 |
$control_name = $control->getOption('name'); |
| 85 |
$control_name_class = $control_name |
| 86 |
? 'factory-control-' . $control_name |
| 87 |
: ''; |
| 88 |
|
| 89 |
$col_left = $control->getLayoutOption('column-left', '2'); |
| 90 |
$col_right = $control->getLayoutOption('column-right', '10'); |
| 91 |
?> |
| 92 |
<div class="form-group form-group-<?php echo esc_attr($control->getType()); ?> <?php echo esc_attr($theme_class); ?> <?php echo esc_attr($control_name_class); ?>"> |
| 93 |
<label for="<?php $control->printNameOnForm() ?>" class="col-sm-<?php echo esc_attr($col_left); ?> control-label"> |
| 94 |
<?php if( $control->hasIcon() ) { ?> |
| 95 |
<img class="control-icon" src="<?php $control->icon(); ?>"/> |
| 96 |
<?php } ?> |
| 97 |
<?php |
| 98 |
$hint_type = $control->getLayoutOption('hint-type', 'default'); |
| 99 |
|
| 100 |
$control->title(); |
| 101 |
if( $control->hasHint() ) { |
| 102 |
if( $hint_type == 'icon' ): ?> |
| 103 |
<?php $hint_icon_color = $control->getLayoutOption('hint-icon-color', 'green'); ?> |
| 104 |
<span class="factory-hint-icon factory-hint-icon-<?php echo esc_attr($hint_icon_color); ?>" data-toggle="factory-tooltip" data-placement="right" title="<?php $control->hint(true); ?>"> |
| 105 |
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAQAAABKmM6bAAAAUUlEQVQIHU3BsQ1AQABA0X/komIrnQHYwyhqQ1hBo9KZRKL9CBfeAwy2ri42JA4mPQ9rJ6OVt0BisFM3Po7qbEliru7m/FkY+TN64ZVxEzh4ndrMN7+Z+jXCAAAAAElFTkSuQmCC" alt=""/> |
| 106 |
|
| 107 |
</span> |
| 108 |
<?php endif; ?> |
| 109 |
<?php if( $control->getLayoutOption('hint-position', 'bottom') == 'left' ): ?> |
| 110 |
<div class="help-block"><?php $control->hint() ?></div> |
| 111 |
<?php endif; ?> |
| 112 |
<?php } ?> |
| 113 |
</label> |
| 114 |
<div class="control-group col-sm-<?php echo esc_attr($col_right); ?>"> |
| 115 |
<?php |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* @param Wbcr_FactoryForms480_Control $control |
| 120 |
*/ |
| 121 |
public function afterControl($control) |
| 122 |
{ |
| 123 |
if( $control->getType() == 'hidden' ) { |
| 124 |
return; |
| 125 |
} |
| 126 |
?> |
| 127 |
<?php if( $control->getOption('after', false) ) { ?> |
| 128 |
<span class="factory-after"> |
| 129 |
<?php $control->option('after') ?> |
| 130 |
</span> |
| 131 |
<?php } ?> |
| 132 |
|
| 133 |
<?php |
| 134 |
$hint_type = $control->getLayoutOption('hint-type', 'default'); |
| 135 |
if( $control->hasHint() && $hint_type == 'default' && $control->getLayoutOption('hint-position', 'bottom') == 'bottom' ): |
| 136 |
?> |
| 137 |
<div class="help-block"> |
| 138 |
<?php $control->hint() ?> |
| 139 |
</div> |
| 140 |
<?php endif; ?> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
<?php |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* @param int $index |
| 148 |
* @param int $total |
| 149 |
*/ |
| 150 |
public function startRow($index, $total) |
| 151 |
{ |
| 152 |
?> |
| 153 |
<div class='factory-row factory-row-<?php echo esc_attr($index); ?> factory-row-<?php echo esc_attr($index); ?>-of-<?php echo esc_attr($total); ?>'> |
| 154 |
<div class="form-group form-group"> |
| 155 |
<?php |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* @param int $index |
| 160 |
* @param int $total |
| 161 |
*/ |
| 162 |
public function endRow($index, $total) |
| 163 |
{ |
| 164 |
?> |
| 165 |
</div> |
| 166 |
</div> |
| 167 |
<?php |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* @param Wbcr_FactoryForms480_Control $control |
| 172 |
* @param int $index |
| 173 |
* @param int $total |
| 174 |
*/ |
| 175 |
public function startColumn($control, $index, $total) |
| 176 |
{ |
| 177 |
$index = $total == 2 |
| 178 |
? 4 |
| 179 |
: 3; |
| 180 |
$name = $control->getNameOnForm(); |
| 181 |
?> |
| 182 |
<label for="<?php echo $name ?>" class="col-sm-2 control-label control-label-<?php echo $name ?>"> |
| 183 |
<?php if( $control->hasIcon() ) { ?> |
| 184 |
<img class="control-icon" src="<?php $control->icon() ?>"/> |
| 185 |
<?php } ?> |
| 186 |
<?php $control->title() ?> |
| 187 |
<?php if( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'left' ) { ?> |
| 188 |
<div class="help-block"><?php $control->hint() ?></div> |
| 189 |
<?php } ?> |
| 190 |
</label> |
| 191 |
<div class="control-group control-group-<?php echo $name ?> col-sm-<?php echo $index ?>"> |
| 192 |
<?php |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* @param Wbcr_FactoryForms480_Control $control |
| 197 |
* @param int $index |
| 198 |
* @param int $total |
| 199 |
*/ |
| 200 |
public function endColumn($control, $index, $total) |
| 201 |
{ |
| 202 |
?> |
| 203 |
<?php if( $control->getOption('after', false) ) { ?> |
| 204 |
<span class="factory-after"> |
| 205 |
<?php $control->option('after') ?> |
| 206 |
</span> |
| 207 |
<?php } ?> |
| 208 |
<?php if( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'bottom' ) { ?> |
| 209 |
<div class="help-block"> |
| 210 |
<?php $control->hint() ?> |
| 211 |
</div> |
| 212 |
<?php } ?> |
| 213 |
</div> |
| 214 |
<?php |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|