Icon.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\GlobalElements; |
| 4 | use Kubio\Core\Element; |
| 5 | use Kubio\Core\LodashBasic; |
| 6 | class Icon extends Element { |
| 7 | public function __construct( $tag_name, $props = array(), $children = array(), $block = null ) { |
| 8 | $defaultIcon = 'font-awesome/star'; |
| 9 | $icon = LodashBasic::get( $props, 'name', $defaultIcon ); |
| 10 | if ( ! $icon ) { |
| 11 | $icon = $defaultIcon; |
| 12 | } |
| 13 | $svg = ''; |
| 14 | if ( $icon && is_string( $icon ) ) { |
| 15 | $icon_folder_name = explode( '/', $icon ); |
| 16 | $svg_file = ( KUBIO_ROOT_DIR . 'static/icons/' . sanitize_file_name( $icon_folder_name[0] ) . '/' . $icon_folder_name[1] . '.svg' ); |
| 17 | if ( file_exists( $svg_file ) ) { |
| 18 | $svg = file_get_contents( $svg_file ); |
| 19 | } |
| 20 | } |
| 21 | parent::__construct( |
| 22 | Element::SPAN, |
| 23 | LodashBasic::merge( |
| 24 | $props, |
| 25 | array( |
| 26 | 'className' => array( 'h-svg-icon' ), |
| 27 | ) |
| 28 | ), |
| 29 | array( $svg ), |
| 30 | $block |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | public function __toString() { |
| 35 | return parent::__toString(); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 |