LayoutHelper.php
3 years ago
MetaInformationManager.php
2 months ago
PostContentManager.php
10 months ago
PostListTransformer.php
3 years ago
PostTransformer.php
1 year ago
PostTransformerContentsExtractor.php
2 months ago
StructureTransformer.php
3 years ago
TitleListTransformer.php
1 year ago
Transformer.php
3 years ago
index.php
3 years ago
TitleListTransformer.php
61 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Newsletter\Editor; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class TitleListTransformer { |
| 11 | |
| 12 | private $args; |
| 13 | |
| 14 | public function __construct( |
| 15 | $args |
| 16 | ) { |
| 17 | $this->args = $args; |
| 18 | } |
| 19 | |
| 20 | public function transform($posts) { |
| 21 | $results = array_map(function($post) { |
| 22 | return $this->getPostTitle($post); |
| 23 | }, $posts); |
| 24 | |
| 25 | return [ |
| 26 | $this->wrap([ |
| 27 | 'type' => 'text', |
| 28 | 'text' => '<ul>' . implode('', $results) . '</ul>', |
| 29 | ])]; |
| 30 | } |
| 31 | |
| 32 | private function wrap($block) { |
| 33 | return LayoutHelper::row([ |
| 34 | LayoutHelper::col([$block]), |
| 35 | ]); |
| 36 | } |
| 37 | |
| 38 | private function getPostTitle($post) { |
| 39 | if ($this->isWcProduct($post)) { |
| 40 | $title = $post->get_name(); |
| 41 | $postId = $post->get_id(); |
| 42 | } else { |
| 43 | $title = $post->post_title; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 44 | $postId = $post->ID; |
| 45 | } |
| 46 | |
| 47 | $alignment = $this->args['titleAlignment']; |
| 48 | $alignment = (in_array($alignment, ['left', 'right', 'center'])) ? $alignment : 'left'; |
| 49 | |
| 50 | if ($this->args['titleIsLink']) { |
| 51 | $title = '<a data-post-id="' . $postId . '" href="' . WPFunctions::get()->getPermalink($postId) . '">' . $title . '</a>'; |
| 52 | } |
| 53 | |
| 54 | return '<li style="text-align: ' . $alignment . ';">' . $title . '</li>'; |
| 55 | } |
| 56 | |
| 57 | private function isWcProduct($post) { |
| 58 | return class_exists('\WC_Product') && $post instanceof \WC_Product; |
| 59 | } |
| 60 | } |
| 61 |