summaryrefslogtreecommitdiff
path: root/smartyplugins/BlockLegend.php
blob: f185fc421904e3384909b9e7f49f30ff46c8fc0e (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
<?php
namespace Bitweaver\Plugins;

use Smarty\BlockHandler\BlockHandlerInterface;
use Smarty\Template;
use Bitweaver\KernelTools;

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

/**
 * Smarty {form} block plugin
 *
 * Type:     block
 * Name:     form
 * Input:
 *           - legend      (optional) - text that appears in the legend
 */
class BlockLegend implements BlockHandlerInterface {

	public function handle( $params, $content, Template $template, &$repeat): string {
		if( $content ) {
			$attributes = '';
			$attributes .= !empty( $params['class'] ) ? ' class="'.$params['class'].'" ' : '' ;
			$attributes .= !empty( $params['id'] ) ? ' id="'.$params['id'].'" ' : '' ;
			$ret = '<fieldset '.$attributes.'>';
			if( !empty( $params['legend'] ) ) {
				$ret .= '<legend>'.KernelTools::tra( $params['legend'] ).'</legend>';
			}
			$ret .= $content;
			$ret .= '</fieldset>';
			return $ret;
		}
		return '';
	}

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