Skip to content

Commit

Permalink
fix(module): move settings to dedicated page
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 13, 2023
1 parent 0297ce0 commit 138ed5c
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 81 deletions.
8 changes: 8 additions & 0 deletions controllers/MyParcelNLAdminSettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
/** @noinspection PhpUnused */

declare(strict_types=1);

use MyParcelNL\PrestaShop\Controller\SettingsController;

final class MyParcelNLAdminSettingsController extends SettingsController { }
48 changes: 0 additions & 48 deletions controllers/admin/AdminMyParcelNLController.php

This file was deleted.

17 changes: 17 additions & 0 deletions myparcelnl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use MyParcelNL\Pdk\Base\Pdk as PdkInstance;
use MyParcelNL\Pdk\Facade\Installer;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\PrestaShop\Hooks\HasPdkCheckoutDeliveryOptionsHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkCheckoutHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkOrderHooks;
use MyParcelNL\PrestaShop\Hooks\HasPdkProductHooks;
Expand All @@ -25,6 +26,7 @@
*/
class MyParcelNL extends CarrierModule
{
use HasPdkCheckoutDeliveryOptionsHooks;
use HasPdkCheckoutHooks;
use HasPdkOrderHooks;
use HasPdkProductHooks;
Expand Down Expand Up @@ -106,6 +108,21 @@ public static function getModule(): self
return $module;
}

/**
* Redirects the "configure" button in the module list to the settings page.
*
* @return string
* @see \MyParcelNL\PrestaShop\Controller\SettingsController
*/
public function getContent(): string
{
$link = $this->context->link->getAdminLink(Pdk::get('legacyControllerSettings'));

Tools::redirectAdmin($link);

return '';
}

/**
* @param \Cart $params
* @param \int $shipping_cost
Expand Down
22 changes: 22 additions & 0 deletions src/Controller/AbstractAdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Controller;

use MyParcelNL;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;

/**
* @property \MyParcelNL $module
*/
abstract class AbstractAdminController extends FrameworkBundleAdminController
{
public function __construct()
{
parent::__construct();

// Trigger PDK setup
new MyParcelNL();
}
}
13 changes: 0 additions & 13 deletions src/Controller/AdminController.php

This file was deleted.

24 changes: 24 additions & 0 deletions src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Controller;

use MyParcelNL\Pdk\Facade\Frontend;
use Symfony\Component\HttpFoundation\Response;

/**
* @property \MyParcelNL $module
*/
class SettingsController extends AbstractAdminController
{
/**
* @return Response
*/
public function index(): Response
{
return $this->render('@Modules/myparcelnl/views/templates/admin/page.twig', [
'content' => Frontend::renderPluginSettings(),
]);
}
}
10 changes: 0 additions & 10 deletions src/Hooks/HasPdkRenderHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@

trait HasPdkRenderHooks
{
/**
* Renders the module configuration page.
*
* @return string
*/
public function getContent(): string
{
return Frontend::renderPluginSettings();
}

/**
* Add columns to the order grid to render the order boxes in.
*
Expand Down
24 changes: 20 additions & 4 deletions src/Pdk/Base/PsPdkBootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,35 @@ protected function getConfig(string $version, string $name): array
'MyParcel-PrestaShop' => $version,
]),

'moduleTabName' => value('shipping_logistics'),

'prestaShopVersionMin' => value('1.7.6'),
'prestaShopVersionMax' => value('8.2.0'),

/**
* Tab in the modules list we want to show the module under.
*/

'moduleTabName' => value('shipping_logistics'),

/**
* The name of the tab we want to show the settings page under.
*/

'sidebarParentClass' => value('AdminParentShipping'),

'logDirectory' => value(sprintf('%s/var/logs/%s', _PS_ROOT_DIR_, $name)),

/**
* The symfony routes that are used by the pdk.
* The symfony routes that are used by the pdk. Must match the routes in config/routes.yml.
*
* @see config/routes.yml
*/

'routeNamePdk' => value('myparcelnl_pdk'),
'routeNameFrontend' => value('myparcelnl_frontend'),
'routeNamePdk' => value('myparcelnl_pdk'),
'routeNameSettings' => value('myparcelnl_settings'),
'routeNameWebhook' => value('myparcelnl_webhook'),

'legacyControllerSettings' => value('MyParcelNLAdminSettings'),

'moduleInstance' => factory(static function (): Module {
$name = Pdk::getAppInfo()->name;
Expand Down
3 changes: 2 additions & 1 deletion src/Pdk/Frontend/Service/PsViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MyParcelNL\PrestaShop\Pdk\Frontend\Service;

use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\Pdk\Frontend\Service\AbstractViewService;
use PrestaShop\PrestaShop\Adapter\Entity\Dispatcher;
use RuntimeException;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function isOrderPage(): bool
*/
public function isPluginSettingsPage(): bool
{
return 'AdminModules' === $this->getPage();
return Pdk::get('legacyControllerSettings') === $this->getPage();
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/Pdk/Installer/Service/PsInstallerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,16 @@ private function installDatabase(): void
*/
private function installTabs(): void
{
$languages = array_fill_keys(array_column(Language::getLanguages(), 'id_lang'), Pdk::getAppInfo()->title);

/** @var \PrestaShopBundle\Entity\Repository\TabRepository $tabRepository */
$tabRepository = Pdk::get('ps.tabRepository');

$tab = new Tab();

$tab->active = 1;
$tab->class_name = 'AdminMyParcelNL';
$tab->name = $languages;
$tab->id_parent = $tabRepository->findOneIdByClassName('AdminParentShipping');
$tab->class_name = Pdk::get('legacyControllerSettings');
$tab->route_name = Pdk::get('routeNameSettings');
$tab->name = array_fill_keys(array_column(Language::getLanguages(), 'id_lang'), Pdk::getAppInfo()->title);
$tab->id_parent = $tabRepository->findOneIdByClassName(Pdk::get('sidebarParentClass'));
$tab->module = $this->module->name;

if (! $tab->add()) {
Expand Down
5 changes: 5 additions & 0 deletions views/templates/admin/page.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@PrestaShop/Admin/layout.html.twig' %}

{% block content %}
{{ content | raw }}
{% endblock %}

0 comments on commit 138ed5c

Please sign in to comment.