| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sendy\WooCommerce\Modules\Admin\Fields; |
| 4 |
|
| 5 |
use Sendy\WooCommerce\Utils\View; |
| 6 |
|
| 7 |
abstract class Field |
| 8 |
{ |
| 9 |
protected string $optionName; |
| 10 |
protected ?string $extraDescription; |
| 11 |
|
| 12 |
protected View $view; |
| 13 |
|
| 14 |
public function __construct( |
| 15 |
string $optionName, |
| 16 |
string $extraDescription = null |
| 17 |
) { |
| 18 |
$this->optionName = $optionName; |
| 19 |
$this->extraDescription = $extraDescription; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Initialize the view which is used to render the field |
| 24 |
* |
| 25 |
* This method is called from the render method when rendering the view. Therefor it's only necessary to implement |
| 26 |
* this method on the child classes without calling it. |
| 27 |
*/ |
| 28 |
abstract public function initializeView(): void; |
| 29 |
|
| 30 |
final public function render(array $parameters = []): void |
| 31 |
{ |
| 32 |
$this->initializeView(); |
| 33 |
|
| 34 |
echo wp_kses( |
| 35 |
$this->view->render(array_merge($parameters, [ |
| 36 |
'option_name' => $this->optionName, |
| 37 |
'extra_description' => $this->extraDescription, |
| 38 |
])), |
| 39 |
View::ALLOWED_TAGS, |
| 40 |
); |
| 41 |
} |
| 42 |
} |
| 43 |
|