Skip to content

Commit

Permalink
Pass container to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jan 31, 2025
1 parent 922da6d commit 536c71d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/Settings/MollieSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Mollie\WooCommerce\Settings\Page\PageNoApiKey;
use Mollie\WooCommerce\Settings\Page\PagePaymentMethods;
use Mollie\WooCommerce\Shared\Data;
use Psr\Container\ContainerInterface;
use WC_Admin_Settings;
use WC_Settings_Page;

Expand All @@ -22,6 +23,7 @@ class MollieSettingsPage extends WC_Settings_Page
protected array $paymentMethods;
protected bool $isTestModeEnabled;
protected Data $dataHelper;
protected ContainerInterface $container;

public function __construct(
Settings $settings,
Expand All @@ -30,7 +32,8 @@ public function __construct(
array $mollieGateways,
array $paymentMethods,
bool $isTestModeEnabled,
Data $dataHelper
Data $dataHelper,
ContainerInterface $container
) {

$this->id = 'mollie_settings';
Expand All @@ -42,6 +45,7 @@ public function __construct(
$this->isTestModeEnabled = $isTestModeEnabled;
$this->dataHelper = $dataHelper;
$this->paymentMethods = $paymentMethods;
$this->container = $container;
$this->registerContentFieldType();
$this->outputSections();
parent::__construct();
Expand Down Expand Up @@ -128,7 +132,8 @@ public function get_settings($currentSection = '')
$this->isTestModeEnabled,
$this->mollieGateways,
$this->paymentMethods,
$this->dataHelper
$this->dataHelper,
$this->container
);
if ($page::slug() === $defaultSection) {
$mollieSettings = $this->hideKeysIntoStars($page->settings());
Expand Down
9 changes: 7 additions & 2 deletions src/Settings/Page/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mollie\WooCommerce\Settings\Page\Section\AbstractSection;
use Mollie\WooCommerce\Settings\Settings;
use Mollie\WooCommerce\Shared\Data;
use Psr\Container\ContainerInterface;

abstract class AbstractPage
{
Expand All @@ -19,6 +20,7 @@ abstract class AbstractPage
protected array $mollieGateways;
protected array $paymentMethods;
protected Data $dataHelper;
protected ContainerInterface $container;

public function __construct(
Settings $settings,
Expand All @@ -29,7 +31,8 @@ public function __construct(
bool $testModeEnabled,
array $mollieGateways,
array $paymentMethods,
Data $dataHelper
Data $dataHelper,
ContainerInterface $container
) {

$this->settings = $settings;
Expand All @@ -41,6 +44,7 @@ public function __construct(
$this->mollieGateways = $mollieGateways;
$this->paymentMethods = $paymentMethods;
$this->dataHelper = $dataHelper;
$this->container = $container;
}

abstract public static function isTab(): bool;
Expand Down Expand Up @@ -73,7 +77,8 @@ public function settings(): array
$this->testModeEnabled,
$this->mollieGateways,
$this->paymentMethods,
$this->dataHelper
$this->dataHelper,
$this->container
);
foreach ($section->config() as $field) {
$settings[] = $field;
Expand Down
6 changes: 5 additions & 1 deletion src/Settings/Page/Section/AbstractSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Mollie\WooCommerce\Settings\Settings;
use Mollie\WooCommerce\Shared\Data;
use Psr\Container\ContainerInterface;

abstract class AbstractSection
{
Expand All @@ -18,6 +19,7 @@ abstract class AbstractSection
protected array $mollieGateways;
protected array $paymentMethods;
protected Data $dataHelper;
protected ContainerInterface $container;

public function __construct(
Settings $settings,
Expand All @@ -28,7 +30,8 @@ public function __construct(
bool $testModeEnabled,
array $mollieGateways,
array $paymentMethods,
Data $dataHelper
Data $dataHelper,
ContainerInterface $container
) {

$this->settings = $settings;
Expand All @@ -40,6 +43,7 @@ public function __construct(
$this->mollieGateways = $mollieGateways;
$this->paymentMethods = $paymentMethods;
$this->dataHelper = $dataHelper;
$this->container = $container;
}

abstract public function config(): array;
Expand Down
10 changes: 6 additions & 4 deletions src/Settings/Page/Section/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function renderGateways(): string
'mollie-payments-for-woocommerce'
);
$descriptionActivePaymentMethods = __(
'These payment methods are active in your Mollie profile.
'These payment methods are active in your Mollie profile.
You can enable these payment methods in their settings to make them available for your customers.',
'mollie-payments-for-woocommerce'
);
$titleInactivePaymentMethods = __('Inactive Payment Methods', 'mollie-payments-for-woocommerce');
$descriptionInactivePaymentMethods = __(
'These payment methods are available in your Mollie profile but are
'These payment methods are available in your Mollie profile but are
not currently active. Activate them to offer more payment options to your customers.',
'mollie-payments-for-woocommerce'
);
Expand Down Expand Up @@ -228,12 +228,14 @@ protected function paymentGatewayButton(AbstractPaymentMethod $paymentMethod, $e
esc_html(__('Activate Payment Method', 'mollie-payments-for-woocommerce'))
. '</a>';
}
$iconProvider = $paymentMethod->paymentMethodIconProvider($this->container);
$icon = $iconProvider->provideIcons()[0];

ob_start();
?>
<div class="mollie-settings-pm__single">
<?= $paymentMethod->getIconUrl(); // WPCS: XSS ok.?>
<?= esc_html($paymentMethod->title());?>
<?= $icon->src(); // WPCS: XSS ok.?>
<?= esc_html($paymentMethod->title($this->container));?>
<?= $messageOrLink; // WPCS: XSS ok.?>
<?= $button; // WPCS: XSS ok.?>
</div>
Expand Down
17 changes: 13 additions & 4 deletions src/Settings/SettingsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ function () use ($optionName, $defaultAdvancedOptions, $defaultComponentsOptions

$gateways = $container->get('__deprecated.gateway_helpers');
$isSDDGatewayEnabled = $container->get('gateway.isSDDGatewayEnabled');
$this->initMollieSettingsPage($isSDDGatewayEnabled, $gateways, $pluginPath, $pluginUrl, $paymentMethods);
$this->initMollieSettingsPage(
$isSDDGatewayEnabled,
$gateways,
$pluginPath,
$pluginUrl,
$paymentMethods,
$container
);
add_action(
'woocommerce_admin_settings_sanitize_option',
[$this->settingsHelper, 'updateMerchantIdOnApiKeyChanges'],
Expand Down Expand Up @@ -250,25 +257,27 @@ public function maybeSaveDefaultSettings($optionName, $testOption, $defaultOptio
* @param $pluginPath
* @param $pluginUrl
* @param $paymentMethods
* @param $container
* @return void
*/
protected function initMollieSettingsPage($isSDDGatewayEnabled, $gateways, $pluginPath, $pluginUrl, $paymentMethods): void
protected function initMollieSettingsPage($isSDDGatewayEnabled, $gateways, $pluginPath, $pluginUrl, $paymentMethods, $container): void
{
if (!$isSDDGatewayEnabled) {
//remove directdebit gateway from gateways list
unset($gateways['mollie_wc_gateway_directdebit']);
}
add_filter(
'woocommerce_get_settings_pages',
function ($settings) use ($pluginPath, $pluginUrl, $gateways, $paymentMethods) {
function ($settings) use ($pluginPath, $pluginUrl, $gateways, $paymentMethods, $container) {
$settings[] = new MollieSettingsPage(
$this->settingsHelper,
$pluginPath,
$pluginUrl,
$gateways,
$paymentMethods,
$this->isTestModeEnabled,
$this->dataHelper
$this->dataHelper,
$container
);

return $settings;
Expand Down

0 comments on commit 536c71d

Please sign in to comment.