BlockRendererHelper.php
1 month 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
1 month 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
Columns.php
70 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 Columns { |
| 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 class='mailpoet_form_columns_container'><div {$this->getClass($block['params'] ?? [])}{$this->getStyles($block['params'] ?? [])}>$content</div></div>"; |
| 22 | } |
| 23 | |
| 24 | private function getStyles(array $params): string { |
| 25 | $styles = []; |
| 26 | if (!empty($params['text_color'])) { |
| 27 | $styles[] = "color:{$params['text_color']};"; |
| 28 | } |
| 29 | if (!empty($params['background_color'])) { |
| 30 | $styles[] = "background-color:{$params['background_color']};"; |
| 31 | } |
| 32 | if (!empty($params['gradient'])) { |
| 33 | $styles[] = "background:{$params['gradient']};"; |
| 34 | } |
| 35 | if (!empty($params['padding']) && is_array($params['padding'])) { |
| 36 | $top = is_scalar($params['padding']['top'] ?? null) ? (string)$params['padding']['top'] : '0'; |
| 37 | $right = is_scalar($params['padding']['right'] ?? null) ? (string)$params['padding']['right'] : '0'; |
| 38 | $bottom = is_scalar($params['padding']['bottom'] ?? null) ? (string)$params['padding']['bottom'] : '0'; |
| 39 | $left = is_scalar($params['padding']['left'] ?? null) ? (string)$params['padding']['left'] : '0'; |
| 40 | $styles[] = "padding:{$top} {$right} {$bottom} {$left};"; |
| 41 | } |
| 42 | if (count($styles)) { |
| 43 | return ' style="' . $this->wp->escAttr(implode('', $styles)) . '"'; |
| 44 | } |
| 45 | return ''; |
| 46 | } |
| 47 | |
| 48 | private function getClass(array $params): string { |
| 49 | $classes = ['mailpoet_form_columns mailpoet_paragraph']; |
| 50 | if (!empty($params['vertical_alignment'])) { |
| 51 | $classes[] = "mailpoet_vertically_align_{$params['vertical_alignment']}"; |
| 52 | } |
| 53 | if (!empty($params['background_color']) || !empty($params['gradient'])) { |
| 54 | $classes[] = "mailpoet_column_with_background"; |
| 55 | } |
| 56 | if (!empty($params['text_color'])) { |
| 57 | $classes[] = "has-{$params['text_color']}-color"; |
| 58 | } |
| 59 | // BC !isset for older forms that were saved without the flag |
| 60 | if (!isset($params['is_stacked_on_mobile']) || $params['is_stacked_on_mobile'] === '1') { |
| 61 | $classes[] = "mailpoet_stack_on_mobile"; |
| 62 | } |
| 63 | if (!empty($params['class_name'])) { |
| 64 | $classes[] = $params['class_name']; |
| 65 | } |
| 66 | $classes = implode(' ', $classes); |
| 67 | return "class=\"{$this->wp->escAttr($classes)}\""; |
| 68 | } |
| 69 | } |
| 70 |