DataTransferObjects
3 years ago
Endpoints
3 years ago
ListTable
3 years ago
Models
3 years ago
Properties
3 years ago
Repositories
3 years ago
ValueObjects
3 years ago
resources
3 years ago
DonationFormsAdminPage.php
3 years ago
ServiceProvider.php
3 years ago
ServiceProvider.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationForms; |
| 4 | |
| 5 | use Give\DonationForms\ListTable\DonationFormsListTable; |
| 6 | use Give\DonationForms\Repositories\DonationFormsRepository; |
| 7 | use Give\Helpers\Hooks; |
| 8 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 9 | |
| 10 | /** |
| 11 | * @since 2.19.0 |
| 12 | */ |
| 13 | class ServiceProvider implements ServiceProviderInterface |
| 14 | { |
| 15 | /** |
| 16 | * @inheritDoc |
| 17 | */ |
| 18 | public function register() |
| 19 | { |
| 20 | give()->singleton('donationForms', DonationFormsRepository::class); |
| 21 | give()->singleton(DonationFormsListTable::class, function() { |
| 22 | $listTable = new DonationFormsListTable(); |
| 23 | Hooks::doAction('givewp_donation_forms_list_table', $listTable); |
| 24 | |
| 25 | return $listTable; |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | */ |
| 32 | public function boot() |
| 33 | { |
| 34 | $userId = get_current_user_id(); |
| 35 | $showLegacy = get_user_meta($userId, '_give_donation_forms_archive_show_legacy', true); |
| 36 | // only register new admin page if user hasn't chosen to use the old one |
| 37 | if(empty($showLegacy)) |
| 38 | { |
| 39 | Hooks::addAction('admin_menu', DonationFormsAdminPage::class, 'register', 0); |
| 40 | Hooks::addAction('admin_menu', DonationFormsAdminPage::class, 'highlightAllFormsMenuItem'); |
| 41 | |
| 42 | if (DonationFormsAdminPage::isShowing()) { |
| 43 | Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadScripts'); |
| 44 | } |
| 45 | } |
| 46 | elseif(DonationFormsAdminPage::isShowingLegacyPage()) |
| 47 | { |
| 48 | Hooks::addAction( 'admin_head', DonationFormsAdminPage::class, 'renderReactSwitch'); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 |