summaryrefslogtreecommitdiff
path: root/smartyplugins/BlockFormInput.php
blob: f46cf2118ca50cef99940c08ebc13951d53886ec (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Bitweaver\Plugins;

use Smarty\BlockHandler\BlockHandlerInterface;
use Smarty\Template;

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty {forminput} block plugin
 *
 * Type:     block
 * Name:     forminput
 */
class BlockFormInput implements BlockHandlerInterface {

	public function handle( $params, $content, Template $template, &$repeat): string {
		global $gSmartyFormHorizontal;

		// defaults
		$attr = "";
		$class = '';
		if( $gSmartyFormHorizontal ) {
			$class = 'col-sm-8';
		}

		if( !empty( $params['class'] ) ){
			$class .= ' '.trim( $params['class'] );
			if( $gSmartyFormHorizontal && (strpos( $params['class'], 'submit' ) !== FALSE || strpos( $params['class'], 'offset' ) !== FALSE) ) {
				$class .= ' col-sm-offset-4';
			}
		}

		$labelStart = '';
		$labelEnd = '';

		if( !empty( $params['label'] ) ){
			if( $gSmartyFormHorizontal ) {
				$class .= ' col-sm-offset-4';
			}
			$class .= ' '.trim( $params['label'] );
			$labelStart = '<label>';
			$labelEnd = '</label>';
		}

		if( !empty( $params['id'] ) ){
			$attr .= 'id="'.trim( $params['id'] ).'" ';
		}

		if( !empty( $params['style'] ) ){
			$attr .= 'style="'.trim( $params['style'] ).'" ';
		}

		if( $content ) {
			return '<div class="'.$class.'" '.$attr.' >'.$labelStart.$content.$labelEnd.'</div>';
		}
			return '';

	}

	public function isCacheable(): bool {
		return true;
	}
}