Exceptions
1 year ago
PaymentsProviders
5 days ago
SettingsUIPages
1 month ago
LegacySettingsPageAdapter.php
5 days ago
Payments.php
4 months ago
PaymentsController.php
11 months ago
PaymentsProviders.php
2 months ago
PaymentsRestController.php
3 months ago
RegisteredSettingsSectionAdapter.php
3 weeks ago
SettingsSectionNavigation.php
5 days ago
SettingsUIPageInterface.php
1 month ago
SettingsUIRequestContext.php
5 days ago
SettingsUISchema.php
3 weeks ago
Utils.php
3 months ago
LegacySettingsPageAdapter.php
89 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Legacy WC_Settings_Page adapter for settings UI. |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types=1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\Admin\Settings; |
| 9 | |
| 10 | use Automattic\WooCommerce\Admin\Settings\SettingsUIPageInterface as PublicSettingsUIPageInterface; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Adapts a WC_Settings_Page instance into the settings UI page contract. |
| 16 | * |
| 17 | * Internal implementation of the legacy settings adapter. Extensions should use |
| 18 | * Automattic\WooCommerce\Admin\Settings\LegacySettingsPageAdapter. |
| 19 | * |
| 20 | * @since 10.9.0 |
| 21 | */ |
| 22 | class LegacySettingsPageAdapter implements PublicSettingsUIPageInterface { |
| 23 | |
| 24 | /** |
| 25 | * Legacy settings page. |
| 26 | * |
| 27 | * @var \WC_Settings_Page |
| 28 | */ |
| 29 | protected \WC_Settings_Page $settings_page; |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | * |
| 34 | * @since 10.9.0 |
| 35 | * |
| 36 | * @param \WC_Settings_Page $settings_page Legacy settings page. |
| 37 | */ |
| 38 | public function __construct( \WC_Settings_Page $settings_page ) { |
| 39 | $this->settings_page = $settings_page; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * {@inheritDoc} |
| 44 | */ |
| 45 | public function get_page_id(): string { |
| 46 | return $this->settings_page->get_id(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Build the canonical settings schema for a section. |
| 51 | * |
| 52 | * @param string $section Section id. Empty string means the default section. |
| 53 | * @return array |
| 54 | */ |
| 55 | public function get_schema( string $section ): array { |
| 56 | $schema = SettingsUISchema::from_legacy_settings( |
| 57 | $this->settings_page->get_id(), |
| 58 | $section, |
| 59 | $this->settings_page->get_label(), |
| 60 | $this->settings_page->get_settings( $section ), |
| 61 | $this->get_save_adapter( $section ) |
| 62 | ); |
| 63 | |
| 64 | $schema['shell']['sectionNavigation'] = SettingsSectionNavigation::build_default( $this->settings_page, $section ); |
| 65 | |
| 66 | return $schema; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get script handles that must be loaded before the settings UI app mounts. |
| 71 | * |
| 72 | * @param string $section Section id. Empty string means the default section. |
| 73 | * @return string[] |
| 74 | */ |
| 75 | public function get_script_handles( string $section ): array { |
| 76 | return array(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get the default save adapter for fields on this page. |
| 81 | * |
| 82 | * @param string $section Section id. Empty string means the default section. |
| 83 | * @return string |
| 84 | */ |
| 85 | public function get_save_adapter( string $section ): string { |
| 86 | return 'form_post'; |
| 87 | } |
| 88 | } |
| 89 |