Block.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\StoreLogo; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\BaseBlock; |
| 6 | |
| 7 | /** |
| 8 | * Logout Button Block. |
| 9 | */ |
| 10 | class Block extends BaseBlock { |
| 11 | /** |
| 12 | * Render the block |
| 13 | * |
| 14 | * @param array $attributes Block attributes. |
| 15 | * @param string $content Post content. |
| 16 | * |
| 17 | * @return string |
| 18 | */ |
| 19 | public function render( $attributes, $content ) { |
| 20 | $logo = \SureCart::account()->brand->logo_url; |
| 21 | |
| 22 | if ( empty( $logo ) ) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | $styles = 'object-fit: contain; object-position: left;'; |
| 27 | if ( ! empty( $attributes['width'] ) ) { |
| 28 | $styles .= 'width: ' . $attributes['width'] . 'px; '; |
| 29 | $styles .= 'max-width: ' . $attributes['maxWidth'] . 'px; '; |
| 30 | } |
| 31 | if ( ! empty( $attributes['maxHeight'] ) ) { |
| 32 | $styles .= 'max-height: ' . $attributes['maxHeight'] . 'px; '; |
| 33 | } |
| 34 | |
| 35 | ob_start(); ?> |
| 36 | |
| 37 | <div> |
| 38 | |
| 39 | <?php if ( $attributes['isLinkToHome'] ) { ?> |
| 40 | <a href="<?php echo esc_url( get_home_url() ); ?>" style="<?php echo esc_attr( $this->getStyles( $attributes ) ); ?> rel="home"> |
| 41 | <?php } else { ?> |
| 42 | <div style="<?php echo esc_attr( $this->getStyles( $attributes ) ); ?>"> |
| 43 | <?php } ?> |
| 44 | |
| 45 | <img |
| 46 | src="<?php echo esc_url( $logo ); ?>" |
| 47 | style="<?php echo esc_attr( $styles ); ?>" |
| 48 | alt="" |
| 49 | /> |
| 50 | |
| 51 | <?php if ( $attributes['isLinkToHome'] ) { ?> |
| 52 | </a> |
| 53 | <?php } else { ?> |
| 54 | </div> |
| 55 | <?php } ?> |
| 56 | |
| 57 | </div> |
| 58 | |
| 59 | <?php |
| 60 | return ob_get_clean(); |
| 61 | } |
| 62 | } |
| 63 |