class-abstract-pattern.php
131 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the WooCommerce Email Editor package |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\EmailEditor |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types = 1); |
| 9 | namespace Automattic\WooCommerce\EmailEditor\Engine\Patterns; |
| 10 | |
| 11 | /** |
| 12 | * Abstract class for block patterns. |
| 13 | */ |
| 14 | abstract class Abstract_Pattern { |
| 15 | /** |
| 16 | * Name of the pattern. |
| 17 | * |
| 18 | * @var string $name |
| 19 | */ |
| 20 | protected $name = ''; |
| 21 | /** |
| 22 | * Namespace of the pattern. |
| 23 | * |
| 24 | * @var string $namespace |
| 25 | */ |
| 26 | protected $namespace = ''; |
| 27 | /** |
| 28 | * List of block types. |
| 29 | * |
| 30 | * @var array $block_types |
| 31 | */ |
| 32 | protected $block_types = array(); |
| 33 | /** |
| 34 | * List of template types. |
| 35 | * |
| 36 | * @var string[] $template_types |
| 37 | */ |
| 38 | protected $template_types = array(); |
| 39 | /** |
| 40 | * List of supported post types. |
| 41 | * |
| 42 | * @var string[] $post_types |
| 43 | */ |
| 44 | protected $post_types = array(); |
| 45 | /** |
| 46 | * Flag to enable/disable inserter. |
| 47 | * |
| 48 | * @var bool $inserter |
| 49 | */ |
| 50 | protected $inserter = true; |
| 51 | /** |
| 52 | * Source of the pattern. |
| 53 | * |
| 54 | * @var string $source |
| 55 | */ |
| 56 | protected $source = 'plugin'; |
| 57 | /** |
| 58 | * List of categories. |
| 59 | * |
| 60 | * @var array $categories |
| 61 | */ |
| 62 | protected $categories = array(); |
| 63 | /** |
| 64 | * Viewport width. |
| 65 | * |
| 66 | * @var int $viewport_width |
| 67 | */ |
| 68 | protected $viewport_width = 620; |
| 69 | |
| 70 | /** |
| 71 | * Get name of the pattern. |
| 72 | * |
| 73 | * @return string |
| 74 | */ |
| 75 | public function get_name(): string { |
| 76 | return $this->name; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get namespace of the pattern. |
| 81 | * |
| 82 | * @return string |
| 83 | */ |
| 84 | public function get_namespace(): string { |
| 85 | return $this->namespace; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Return properties of the pattern. |
| 90 | * |
| 91 | * @return array |
| 92 | */ |
| 93 | public function get_properties(): array { |
| 94 | return array( |
| 95 | 'title' => $this->get_title(), |
| 96 | 'content' => $this->get_content(), |
| 97 | 'description' => $this->get_description(), |
| 98 | 'categories' => $this->categories, |
| 99 | 'inserter' => $this->inserter, |
| 100 | 'blockTypes' => $this->block_types, |
| 101 | 'templateTypes' => $this->template_types, |
| 102 | 'postTypes' => $this->post_types, |
| 103 | 'source' => $this->source, |
| 104 | 'viewportWidth' => $this->viewport_width, |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get content. |
| 110 | * |
| 111 | * @return string |
| 112 | */ |
| 113 | abstract protected function get_content(): string; |
| 114 | |
| 115 | /** |
| 116 | * Get title. |
| 117 | * |
| 118 | * @return string |
| 119 | */ |
| 120 | abstract protected function get_title(): string; |
| 121 | |
| 122 | /** |
| 123 | * Get description. |
| 124 | * |
| 125 | * @return string |
| 126 | */ |
| 127 | protected function get_description(): string { |
| 128 | return ''; |
| 129 | } |
| 130 | } |
| 131 |