New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make modules act like Symfony Bundles #8342
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ class CommonController extends FrameworkBundleAdminController | |
* {% render controller('PrestaShopBundle\\Controller\\Admin\\CommonController::paginationAction', | ||
* {'limit': limit, 'offset': offset, 'total': product_count, 'caller_parameters': pagination_parameters}) %} | ||
* | ||
* @Template | ||
* @Template("@PrestaShop/Admin/Common/pagination.html.twig") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can only override templates using "arobased" notation. This notation is the recommended one in Symfony best practices docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no you are able to overwrite all templates, but if you are allowed for breaking changes just do it in favor of best practices There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello Daniel, I've tried with the alternative syntax and it doesn't work Twig is unable to find the overriden template. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for a clean overwrite you should implemented some some custom Twig loader / resolver as mentioned before about the activeModules. another solution would be to load active without container access. its also done by Shopware https://github.com/shopware/shopware/blob/5.3/engine/Shopware/Kernel.php#L452 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for the templates I'm good thanks to a custom Twig loader as you suggested (thanks again). I'm looking at Shopware code :) edit: what do you think @Quetzacoalt91? |
||
* @param Request $request | ||
* @param integer $limit | ||
* @param integer $offset | ||
|
@@ -149,7 +149,7 @@ public function paginationAction(Request $request, $limit = 10, $offset = 0, $to | |
/** | ||
* This will allow you to retrieve an HTML code with a list of recommended modules depending on the domain. | ||
* | ||
* @Template | ||
* @Template("@PrestaShop/Admin/Common/recommendedModules.html.twig") | ||
* @param string $domain | ||
* @param integer $limit | ||
* @param integer $randomize | ||
|
@@ -200,7 +200,7 @@ public function renderSidebarAction($url, $title = '', $footer = '') | |
{ | ||
$tools = $this->container->get('prestashop.adapter.tools'); | ||
|
||
return $this->render('PrestaShopBundle:Admin:Common/_partials/_sidebar.html.twig', [ | ||
return $this->render('@PrestaShop/Admin/Common/_partials/_sidebar.html.twig', [ | ||
'footer' => $tools->purifyHTML($footer), | ||
'title' => $title, | ||
'url' => urldecode($url), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* 2007-2017 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-2017 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\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\Config\Resource\FileExistenceResource; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Config\FileLocator; | ||
|
||
/** | ||
* Load services stored in installed modules. | ||
*/ | ||
class LoadServicesFromModulesPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$this->registerServicesFromModules($container); | ||
} | ||
|
||
/** | ||
* Load all services registered in every module. | ||
* | ||
* @param ContainerBuilder $container | ||
* @return void | ||
*/ | ||
private function registerServicesFromModules(ContainerBuilder $container) | ||
{ | ||
$installedModules = $container->getParameter('kernel.active_modules'); | ||
|
||
foreach ($this->getModulesPaths() as $modulePath) { | ||
if (in_array($modulePath->getFilename(), $installedModules) | ||
&& file_exists($modulePath.'/config/services.yml') | ||
) { | ||
$loader = new YamlFileLoader($container, new FileLocator($modulePath.'/config/')); | ||
$loader->load('services.yml'); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return \Iterator | ||
*/ | ||
private function getModulesPaths() | ||
{ | ||
return Finder::create()->directories()->in(__DIR__.'/../../../../modules')->depth(0); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Twig is dependant from database now, since we loop into every "enabled" module templates, if any :)