1<?php
2
3namespace ComboStrap\Tag;
4
5use action_plugin_combo_instructionspostprocessing;
6use ComboStrap\CallStack;
7use ComboStrap\ContainerTag;
8use ComboStrap\DataType;
9use ComboStrap\EditButton;
10use ComboStrap\ExceptionBadArgument;
11use ComboStrap\ExceptionNotFound;
12use ComboStrap\ExecutionContext;
13use ComboStrap\Site;
14use ComboStrap\Snippet;
15use ComboStrap\Template\TemplateForComponent;
16use ComboStrap\TemplateEngine;
17use ComboStrap\TagAttribute\Hero;
18use ComboStrap\LogUtility;
19use ComboStrap\PluginUtility;
20use ComboStrap\SiteConfig;
21use ComboStrap\TagAttributes;
22
23/**
24 *
25 */
26class SubscribeTag
27{
28
29
30    const LOGICAL_TAG = "subscribe";
31    const LIST_ID_ATTRIBUTE = "list-id";
32
33    const SIDE_BY_SIDE_TYPE = "side-by-side";
34
35
36    public static function renderEnterXhtml(TagAttributes $attributes): string
37    {
38
39        $executionContext = ExecutionContext::getActualOrCreateFromEnv();
40        $snippetSystem = $executionContext->getSnippetSystem();
41        $snippetSystem->attachJavascriptComboLibrary();
42        $subscribeTag = self::LOGICAL_TAG;
43        $snippetSystem->attachJavascriptFromComponentId($subscribeTag)
44            ->setFormat(Snippet::IIFE_FORMAT);
45        $snippetSystem->attachCssInternalStyleSheet($subscribeTag);
46
47        $success = TemplateForComponent::create($subscribeTag . "-success")->render([]);
48        $data['list-value'] = $attributes->getValueAndRemove(self::LIST_ID_ATTRIBUTE);
49        $data['list-name'] = "listGuid";
50        $data['email-name'] = "subscriberEmail";
51        $data['email-id'] = $executionContext->getIdManager()->generateNewHtmlIdForComponent("$subscribeTag-email");
52        $data['action'] = "https://api.combostrap.com/combo/public/v1.0/list/registration";
53        $data['success-content'] = $success;
54        try {
55            $data['primary-color'] = $executionContext->getConfig()->getPrimaryColor()->toCssValue();
56        } catch (ExceptionNotFound $e) {
57            // none
58        }
59        $form = TemplateForComponent::create($subscribeTag . "-form")->render($data);
60        return $attributes->toHtmlEnterTag("div") . $form . '</div>';
61    }
62
63
64}
65