<?php namespace MailPoet\Form\Block; if (!defined('ABSPATH')) exit; use MailPoet\WP\Functions as WPFunctions; class Divider { /** @var WPFunctions */ private $wp; public function __construct( WPFunctions $wp ) { $this->wp = $wp; } const DEFAULT_ATTRIBUTES = [ 'height' => 1, 'type' => 'divider', 'style' => 'solid', 'dividerHeight' => 1, 'dividerWidth' => 100, 'color' => 'black', ]; public function render($block): string { $classes = ['mailpoet_spacer']; if (isset($block['params']['type']) && $block['params']['type'] === 'divider') { $classes[] = 'mailpoet_has_divider'; } if (!empty($block['params']['class_name'])) { $classes[] = $block['params']['class_name']; } $classAttr = $this->wp->escAttr(join(' ', $classes)); $height = $this->wp->escAttr($block['params']['height'] ?? self::DEFAULT_ATTRIBUTES['height']); return "<div class='{$classAttr}' style='height: {$height}px;'>" . $this->renderDivider($block) . '</div>'; } private function renderDivider(array $block): string { if (isset($block['params']['type']) && $block['params']['type'] === 'spacer') { return ''; } $width = $block['params']['divider_width'] ?? self::DEFAULT_ATTRIBUTES['dividerWidth']; $style = $block['params']['style'] ?? self::DEFAULT_ATTRIBUTES['style']; $dividerHeight = $block['params']['divider_height'] ?? self::DEFAULT_ATTRIBUTES['dividerHeight']; $color = $block['params']['color'] ?? self::DEFAULT_ATTRIBUTES['color']; $dividerStyles = [ "border-top-style: $style", "border-top-width: {$dividerHeight}px", "border-top-color: $color", "height: {$dividerHeight}px", "width: $width%", ]; $style = $this->wp->escAttr(implode(";", $dividerStyles)); return "<div class='mailpoet_divider' data-automation-id='form_divider' style='$style'></div>"; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
BlockRendererHelper.php | File | 6.65 KB | 0644 |
|
Checkbox.php | File | 1.79 KB | 0644 |
|
Column.php | File | 1.85 KB | 0644 |
|
Columns.php | File | 1.81 KB | 0644 |
|
Date.php | File | 7.46 KB | 0644 |
|
Divider.php | File | 1.88 KB | 0644 |
|
Heading.php | File | 2.85 KB | 0644 |
|
Html.php | File | 928 B | 0644 |
|
Image.php | File | 2.88 KB | 0644 |
|
Paragraph.php | File | 2.54 KB | 0644 |
|
Radio.php | File | 2.02 KB | 0644 |
|
Segment.php | File | 2.45 KB | 0644 |
|
Select.php | File | 2.67 KB | 0644 |
|
Submit.php | File | 1.59 KB | 0644 |
|
Text.php | File | 2.26 KB | 0644 |
|
Textarea.php | File | 1.84 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|