forked from trk/FieldtypeFontIconPicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkupFontIconPicker.module
60 lines (49 loc) · 2.15 KB
/
MarkupFontIconPicker.module
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
<?php
/**
* Class MarkupFontIconPicker
*
* @author : İskender TOTOĞLU, @ukyo (community), @trk (Github)
* @website : http://altivebir.com.tr
* @projectWebsite : https://github.com/trk/FieldtypeFontIconPicker
*/
class MarkupFontIconPicker extends WireData implements Module {
public static function getModuleInfo() {
return array(
'title' => "MarkupFontIconPicker",
'summary' => __('Allow you to call icons simply for InputFieldIconPicker inputs.'),
'version' => 17,
'author' => 'İskender TOTOĞLU | @ukyo(community), @trk (Github), http://altivebir.com.tr',
'href' => 'https://github.com/trk/FieldtypeFontIconPicker',
'icon' => 'flag',
'autoload' => true,
'singular' => true
);
}
public function init() {}
/**
* Render Icon Field
*
* @param $icon
* @param array $options
* @return string
*/
public static function render($icon, $options=array()) {
$prefix = (array_key_exists('prefix', $options)) ? $options['prefix'] : 'fa fa-';
$tag = (array_key_exists('tag', $options)) ? $options['tag'] : 'i';
$class = array();
// Set Icon Class
$class[] = $prefix . $icon;
// Get & Set Extra Classes
if(array_key_exists('class', $options) && is_array($options['class'])) foreach($options['class'] as $k => $clss) $class[] = $clss;
if(array_key_exists('class', $options) && !is_array($options['class'])) $class[] = $options['class'];
// Prepare "class" attribute
$class = (!empty($class)) ? " class='" . implode(' ', $class) . "'" : "";
// Get & Set Styles
$style = array();
if(array_key_exists('style', $options) && is_array($options['style'])) foreach($options['style'] as $k => $styl) $style[] = $styl;
if(array_key_exists('style', $options) && !is_array($options['style'])) $style[] = $options['style'];
// Prepare "style" attribute
$style = (!empty($style)) ? " style='" . implode(' ', $style) . "'" : "";
return "<{$tag}{$class}{$style}></{$tag}>";
}
}