| 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 4.10.0 use formTaxonomySettings.css instead of style-formTaxonomySettings.css |
| 29 |
* @since 3.16.0 |
| 30 |
*/ |
| 31 |
public function __invoke() |
| 32 |
{ |
| 33 |
if($this->viewModel->isFormTagsEnabled() || $this->viewModel->isFormCategoriesEnabled()) { |
| 34 |
|
| 35 |
$scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/formTaxonomySettings.asset.php'); |
| 36 |
|
| 37 |
wp_enqueue_script( |
| 38 |
'givewp-builder-taxonomy-settings', |
| 39 |
GIVE_PLUGIN_URL . 'build/formTaxonomySettings.js', |
| 40 |
$scriptAsset['dependencies'], |
| 41 |
$scriptAsset['version'], |
| 42 |
true |
| 43 |
); |
| 44 |
|
| 45 |
Language::setScriptTranslations('givewp-builder-taxonomy-settings'); |
| 46 |
|
| 47 |
wp_enqueue_style( |
| 48 |
'givewp-builder-taxonomy-settings', |
| 49 |
GIVE_PLUGIN_URL . 'build/formTaxonomySettings.css' |
| 50 |
); |
| 51 |
|
| 52 |
wp_add_inline_script('givewp-builder-taxonomy-settings','var giveTaxonomySettings =' . json_encode([ |
| 53 |
'formTagsEnabled' => $this->viewModel->isFormTagsEnabled(), |
| 54 |
'formCategoriesEnabled' => $this->viewModel->isFormCategoriesEnabled(), |
| 55 |
'formTagsSelected' => $this->viewModel->getSelectedFormTags(), |
| 56 |
'formCategoriesAvailable' => $this->viewModel->getFormCategories(), |
| 57 |
'formCategoriesSelected' => $this->viewModel->getSelectedFormCategories(), |
| 58 |
])); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|