Нет описания

Columns.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace MailPoet\Form\Block;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\WP\Functions as WPFunctions;
  5. class Columns {
  6. /** @var WPFunctions */
  7. private $wp;
  8. public function __construct(
  9. WPFunctions $wp
  10. ) {
  11. $this->wp = $wp;
  12. }
  13. public function render(array $block, string $content): string {
  14. return "<div {$this->getClass($block['params'] ?? [])}{$this->getStyles($block['params'] ?? [])}>$content</div>";
  15. }
  16. private function getStyles(array $params): string {
  17. $styles = [];
  18. if (isset($params['text_color'])) {
  19. $styles[] = "color:{$params['text_color']};";
  20. }
  21. if (!empty($params['background_color'])) {
  22. $styles[] = "background-color:{$params['background_color']};";
  23. }
  24. if (isset($params['gradient'])) {
  25. $styles[] = "background:{$params['gradient']};";
  26. }
  27. if (count($styles)) {
  28. return ' style="' . $this->wp->escAttr(implode('', $styles)) . '"';
  29. }
  30. return '';
  31. }
  32. private function getClass(array $params): string {
  33. $classes = ['mailpoet_form_columns mailpoet_paragraph'];
  34. if (!empty($params['vertical_alignment'])) {
  35. $classes[] = "mailpoet_vertically_align_{$params['vertical_alignment']}";
  36. }
  37. if (!empty($params['background_color']) || !empty($params['gradient'])) {
  38. $classes[] = "mailpoet_column_with_background";
  39. }
  40. if (!empty($params['text_color'])) {
  41. $classes[] = "has-{$params['text_color']}-color";
  42. }
  43. // BC !isset for older forms that were saved without the flag
  44. if (!isset($params['is_stacked_on_mobile']) || $params['is_stacked_on_mobile'] === '1') {
  45. $classes[] = "mailpoet_stack_on_mobile";
  46. }
  47. if (!empty($params['class_name'])) {
  48. $classes[] = $params['class_name'];
  49. }
  50. $classes = implode(' ', $classes);
  51. return "class=\"{$this->wp->escAttr($classes)}\"";
  52. }
  53. }