BlockRendererHelper.php
4 weeks ago
Checkbox.php
1 year ago
Close.php
3 weeks ago
Column.php
3 months ago
Columns.php
3 months ago
Date.php
1 year ago
Divider.php
3 years ago
Heading.php
3 months ago
Html.php
1 year ago
Image.php
10 months ago
Paragraph.php
4 weeks ago
Radio.php
1 year ago
Segment.php
2 months ago
Select.php
2 months ago
Submit.php
1 year ago
Text.php
1 year ago
Textarea.php
1 year ago
index.php
3 years ago
Column.php
67 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Form\Block; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class Column { |
| 11 | /** @var WPFunctions */ |
| 12 | private $wp; |
| 13 | |
| 14 | public function __construct( |
| 15 | WPFunctions $wp |
| 16 | ) { |
| 17 | $this->wp = $wp; |
| 18 | } |
| 19 | |
| 20 | public function render(array $block, string $content): string { |
| 21 | return "<div {$this->getClass($block['params'])}{$this->getStyles($block['params'])}>$content</div>"; |
| 22 | } |
| 23 | |
| 24 | private function getStyles(array $params): string { |
| 25 | $styles = []; |
| 26 | if ( |
| 27 | !empty($params['width']) && |
| 28 | (strlen($params['width']) > 0 && ctype_digit(substr($params['width'], 0, 1))) |
| 29 | ) { |
| 30 | $widthValue = $params['width'] . (is_numeric($params['width']) ? '%' : ''); |
| 31 | $styles[] = "flex-basis:{$widthValue}"; |
| 32 | } |
| 33 | if (!empty($params['padding']) && is_array($params['padding'])) { |
| 34 | $top = is_scalar($params['padding']['top'] ?? null) ? (string)$params['padding']['top'] : '0'; |
| 35 | $right = is_scalar($params['padding']['right'] ?? null) ? (string)$params['padding']['right'] : '0'; |
| 36 | $bottom = is_scalar($params['padding']['bottom'] ?? null) ? (string)$params['padding']['bottom'] : '0'; |
| 37 | $left = is_scalar($params['padding']['left'] ?? null) ? (string)$params['padding']['left'] : '0'; |
| 38 | $styles[] = "padding:{$top} {$right} {$bottom} {$left};"; |
| 39 | } |
| 40 | if (!empty($params['text_color'])) { |
| 41 | $styles[] = "color:{$params['text_color']};"; |
| 42 | } |
| 43 | if (!empty($params['background_color'])) { |
| 44 | $styles[] = "background-color:{$params['background_color']};"; |
| 45 | } |
| 46 | if (!empty($params['gradient'])) { |
| 47 | $styles[] = "background:{$params['gradient']};"; |
| 48 | } |
| 49 | if (!count($styles)) { |
| 50 | return ''; |
| 51 | } |
| 52 | return ' style="' . $this->wp->escAttr(implode(';', $styles)) . ';"'; |
| 53 | } |
| 54 | |
| 55 | private function getClass(array $params): string { |
| 56 | $classes = ['mailpoet_form_column']; |
| 57 | if (!empty($params['vertical_alignment'])) { |
| 58 | $classes[] = "mailpoet_vertically_align_{$params['vertical_alignment']}"; |
| 59 | } |
| 60 | if (!empty($params['class_name'])) { |
| 61 | $classes[] = $params['class_name']; |
| 62 | } |
| 63 | $classes = implode(' ', $classes); |
| 64 | return "class=\"{$this->wp->escAttr($classes)}\""; |
| 65 | } |
| 66 | } |
| 67 |