<?php namespace MailPoet\Form\Block; if (!defined('ABSPATH')) exit; use MailPoet\WP\Functions as WPFunctions; class Paragraph { /** @var WPFunctions */ private $wp; public function __construct( WPFunctions $wp ) { $this->wp = $wp; } public function render(array $block): string { $content = ($block['params']['content'] ?? ''); return $this->wrapContent($content, $block); } private function wrapContent(string $content, array $block): string { $attributes = $this->renderAttributes($block); $openTag = $this->getOpenTag($attributes); return $openTag . $content . "</p>"; } private function getOpenTag(array $attributes): string { if (empty($attributes)) { return "<p>"; } return "<p " . join(' ', $attributes) . ">"; } private function renderAttributes(array $block): array { $result = []; $result[] = $this->renderClass($block); $result[] = $this->renderStyle($block); $result = array_filter($result, function ($attribute) { return $attribute !== null; }); return $result; } private function renderClass(array $block) { $classes = ['mailpoet_form_paragraph']; if (isset($block['params']['class_name'])) { $classes[] = $block['params']['class_name']; } if (isset($block['params']['drop_cap']) && $block['params']['drop_cap'] === '1') { $classes[] = 'has-drop-cap'; } if (!empty($block['params']['background_color'])) { $classes[] = 'mailpoet-has-background-color'; } if (!empty($block['params']['font_size'])) { $classes[] = 'mailpoet-has-font-size'; } if (empty($classes)) { return null; } return 'class="' . $this->wp->escAttr(join(' ', $classes)) . '"'; } private function renderStyle(array $block) { $styles = []; if (!empty($block['params']['background_color'])) { $styles[] = 'background-color: ' . $block['params']['background_color']; } if (!empty($block['params']['align'])) { $styles[] = 'text-align: ' . $block['params']['align']; } if (!empty($block['params']['text_color'])) { $styles[] = 'color: ' . $block['params']['text_color']; } if (!empty($block['params']['font_size'])) { $styles[] = 'font-size: ' . $block['params']['font_size'] . 'px'; } if (!empty($block['params']['line_height'])) { $styles[] = 'line-height: ' . $block['params']['line_height']; } if (empty($styles)) { return null; } return 'style="' . $this->wp->escAttr(join('; ', $styles)) . '"'; } }
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 |
|