Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9153 from mickaelandrieu/play-with-admin-controllers
Be able to declare modern controllers in modules
- Loading branch information
Showing
27 changed files
with
894 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
app: | ||
# The main bundle is PrestaShopCoreBundle which will load other dependencies. | ||
resource: "@PrestaShopBundle/Resources/config/routing.yml" | ||
|
||
app_modules: | ||
# Declare routing.yml file in modules/module-name/config folder. | ||
# v1: only YAML format is supported for now. | ||
resource: . | ||
type: module | ||
prefix: /modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
imports: | ||
- { resource: services/bundle_services.yml } | ||
- { resource: services/core_services.yml } | ||
- { resource: services/adapter_services.yml } | ||
- { resource: services/bundle/*.yml } | ||
- { resource: services/core/*.yml } | ||
- { resource: services/adapter/*.yml } | ||
- { resource: services/alias.yml } |
10 changes: 0 additions & 10 deletions
10
src/PrestaShopBundle/Resources/config/services/adapter_services.yml
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/PrestaShopBundle/Resources/config/services/bundle/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
prestashop.bundle.routing.module_route_loader: | ||
class: 'PrestaShopBundle\Routing\YamlModuleLoader' | ||
arguments: | ||
- '@=service("prestashop.module_kernel.repository").getActiveModulesPaths()' | ||
tags: [routing.loader] |
13 changes: 0 additions & 13 deletions
13
src/PrestaShopBundle/Resources/config/services/bundle_services.yml
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/PrestaShopBundle/Resources/config/services/core_services.yml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
namespace PrestaShopBundle\Routing; | ||
|
||
use Symfony\Component\Config\Loader\Loader; | ||
use Symfony\Component\Routing\RouteCollection; | ||
use RuntimeException; | ||
|
||
/** | ||
* This class is responsible of loading routes of enabled modules. | ||
*/ | ||
class YamlModuleLoader extends Loader | ||
{ | ||
/** | ||
* @var array $activeModules The list of activated modules. | ||
*/ | ||
private $activeModulesPaths; | ||
|
||
/** | ||
* @var bool $isLoaded We load the route collection only once per request. | ||
*/ | ||
private $isLoaded = false; | ||
|
||
public function __construct(array $activeModulesPaths) | ||
{ | ||
$this->activeModulesPaths = $activeModulesPaths; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load($resource, $type = null) | ||
{ | ||
if (true === $this->isLoaded) { | ||
throw new RuntimeException('Do not add the "module" loader twice.'); | ||
} | ||
|
||
$routes = new RouteCollection(); | ||
|
||
foreach ($this->activeModulesPaths as $modulePath) { | ||
$routingFile = $modulePath.'/config/routes.yml'; | ||
if (file_exists($routingFile)) { | ||
$loadedRoutes = $this->import($routingFile, 'yaml'); | ||
|
||
$routes->addCollection($loadedRoutes); | ||
} | ||
} | ||
|
||
$this->isLoaded = true; | ||
|
||
return $routes; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($resource, $type = null) | ||
{ | ||
return 'module' === $type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace Tests\PrestaShopBundle\Routing; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Tests\TestCase\Module as HelperModule; | ||
|
||
|
||
class YamlRoutesInModuleTest extends KernelTestCase | ||
{ | ||
/** | ||
* @var Container | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @var Module | ||
*/ | ||
private $module; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() | ||
{ | ||
$kernel = self::createKernel(); | ||
$kernel->boot(); | ||
|
||
$this->container = $kernel->getContainer(); | ||
|
||
HelperModule::addModule('demo'); | ||
|
||
$this->module = $this->container->get('prestashop.core.admin.module.repository')->getModule('demo'); | ||
$this->module->onInstall(); | ||
$this->container->get('prestashop.adapter.cache_clearer')->clearAllCaches(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function tearDown() | ||
{ | ||
HelperModule::removeModule('demo'); | ||
$this->module->onUninstall(); | ||
} | ||
|
||
public function testRoutesAreRegistered() | ||
{ | ||
$router = $this->container->get('router'); | ||
$route = $router->getRouteCollection()->get('demo_admin_demo'); | ||
|
||
self::assertInstanceOf(Route::class, $route); | ||
|
||
self::assertEquals('/modules/demo/demo', $route->getPath()); | ||
self::assertEquals([ | ||
'_controller' => 'PsTest\Controller\Admin\DemoController::demoAction' | ||
], $route->getDefaults()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Demo module | ||
|
||
Demo module, files in vendor folder automatically generated by Composer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "prestashop/ademo", | ||
"description": "A module for testing purposes", | ||
"autoload": { | ||
"psr-4": { | ||
"PsTest\\": "src/" | ||
}, | ||
"exclude-from-classmap": [] | ||
}, | ||
"license": "MIT", | ||
"type": "prestashop-module", | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<module> | ||
<name>demo</name> | ||
<displayName><![CDATA[Module demo]]></displayName> | ||
<version><![CDATA[1]]></version> | ||
<description><![CDATA[A module to test Module routing feature]]></description> | ||
<author><![CDATA[demo]]></author> | ||
<tab><![CDATA[core_feature]]></tab> | ||
<is_configurable>0</is_configurable> | ||
<need_instance>0</need_instance> | ||
<limited_countries></limited_countries> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
demo_admin_demo: | ||
path: demo/demo | ||
methods: [GET] | ||
defaults: | ||
_controller: 'PsTest\Controller\Admin\DemoController::demoAction' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
if (!defined('_PS_VERSION_')) { | ||
exit; | ||
} | ||
|
||
class demo extends Module | ||
{ | ||
public function __construct() | ||
{ | ||
$this->name = 'demo'; | ||
$this->tab = 'front_office_features'; | ||
$this->version = 1.0; | ||
$this->author = 'Šarūnas Jonušas'; | ||
$this->need_instance = 0; | ||
parent::__construct(); | ||
$this->displayName = 'Awesome module'; | ||
$this->description = 'A module to test Module modern routing'; | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
tests/resources/module/demo/src/Controller/Admin/DemoController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PsTest\Controller\Admin; | ||
|
||
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; | ||
|
||
class DemoController extends FrameworkBundleAdminController | ||
{ | ||
public function demoAction() | ||
{ | ||
return $this->render('@Modules/demo/templates/admin/demo.html.twig'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends '@PrestaShop/Admin/layout.html.twig' %} | ||
|
||
{% block content %} | ||
<h1>Modern module Controller</h1> | ||
|
||
<p>Awesome !</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// autoload.php @generated by Composer | ||
|
||
require_once __DIR__ . '/composer/autoload_real.php'; | ||
|
||
return ComposerAutoloaderInit77be78716c0a12958e9a5ba226453e15::getLoader(); |
Oops, something went wrong.