EnqueueFormBuilderAssets.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormTaxonomies\Actions; |
| 4 | |
| 5 | use Give\FormTaxonomies\ViewModels\FormTaxonomyViewModel; |
| 6 | use Give\Framework\Support\Facades\Scripts\ScriptAsset; |
| 7 | use Give\Helpers\Language; |
| 8 | |
| 9 | /** |
| 10 | * @since 3.16.0 |
| 11 | */ |
| 12 | class EnqueueFormBuilderAssets |
| 13 | { |
| 14 | /** |
| 15 | * @var FormTaxonomyViewModel |
| 16 | */ |
| 17 | protected $viewModel; |
| 18 | |
| 19 | /** |
| 20 | * @since 3.16.0 |
| 21 | */ |
| 22 | public function __construct(FormTaxonomyViewModel $viewModel) |
| 23 | { |
| 24 | $this->viewModel = $viewModel; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @since 3.16.0 |
| 29 | */ |
| 30 | public function __invoke() |
| 31 | { |
| 32 | if($this->viewModel->isFormTagsEnabled() || $this->viewModel->isFormCategoriesEnabled()) { |
| 33 | |
| 34 | $scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/formTaxonomySettings.asset.php'); |
| 35 | |
| 36 | wp_enqueue_script( |
| 37 | 'givewp-builder-taxonomy-settings', |
| 38 | GIVE_PLUGIN_URL . 'build/formTaxonomySettings.js', |
| 39 | $scriptAsset['dependencies'], |
| 40 | $scriptAsset['version'], |
| 41 | true |
| 42 | ); |
| 43 | |
| 44 | Language::setScriptTranslations('givewp-builder-taxonomy-settings'); |
| 45 | |
| 46 | wp_enqueue_style( |
| 47 | 'givewp-builder-taxonomy-settings', |
| 48 | GIVE_PLUGIN_URL . 'build/style-formTaxonomySettings.css' |
| 49 | ); |
| 50 | |
| 51 | wp_add_inline_script('givewp-builder-taxonomy-settings','var giveTaxonomySettings =' . json_encode([ |
| 52 | 'formTagsEnabled' => $this->viewModel->isFormTagsEnabled(), |
| 53 | 'formCategoriesEnabled' => $this->viewModel->isFormCategoriesEnabled(), |
| 54 | 'formTagsSelected' => $this->viewModel->getSelectedFormTags(), |
| 55 | 'formCategoriesAvailable' => $this->viewModel->getFormCategories(), |
| 56 | 'formCategoriesSelected' => $this->viewModel->getSelectedFormCategories(), |
| 57 | ])); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |