BlockRenderController.php
26 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Campaigns\Blocks\CampaignComments\Controller; |
| 4 | |
| 5 | use Give\Campaigns\Blocks\CampaignComments\DataTransferObjects\BlockAttributes; |
| 6 | |
| 7 | /** |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | class BlockRenderController |
| 11 | { |
| 12 | /** |
| 13 | * @since 4.0.0 |
| 14 | */ |
| 15 | public function render(array $attributes, string $secondaryColor): string |
| 16 | { |
| 17 | $blockAttributes = BlockAttributes::fromArray($attributes); |
| 18 | |
| 19 | $encodedAttributes = json_encode($blockAttributes->toArray()); |
| 20 | |
| 21 | $blockId = $blockAttributes->blockId; |
| 22 | |
| 23 | return "<div id='givewp-campaign-comments-block-{$blockId}' data-secondary-color='{$secondaryColor}' data-givewp-campaign-comments data-attributes='{$encodedAttributes}'></div>"; |
| 24 | } |
| 25 | } |
| 26 |