Skip to content

Commit

Permalink
fix using new translation system
Browse files Browse the repository at this point in the history
  • Loading branch information
luigimassa committed Mar 10, 2023
1 parent 801dcc6 commit 4cf9135
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 55 deletions.
108 changes: 56 additions & 52 deletions src/Commands/Module/ModuleGenerate.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
/**
* Copyright (c) Since 2020 Friends of Presta
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file docs/licenses/LICENSE.txt.
* It is also available through the world-wide-web at this URL:
Expand All @@ -13,6 +15,7 @@
* @author Friends of Presta <[email protected]>
* @copyright since 2020 Friends of Presta
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0
*
*/

namespace FOP\Console\Commands\Module;
Expand Down Expand Up @@ -43,9 +46,9 @@ public function __construct()
$this->filesystem = new Filesystem();
$this->baseFolder =
'/fop_console/src/Resources/templates/generate_module_command/module';
$this->baseControllerFolder = $this->baseFolder.'/controller';
$this->baseViewFolder = $this->baseFolder.'/views';
$this->baseTestFolder = $this->baseFolder.'/test';
$this->baseControllerFolder = $this->baseFolder . '/controller';
$this->baseViewFolder = $this->baseFolder . '/views';
$this->baseTestFolder = $this->baseFolder . '/test';
}

/**
Expand All @@ -61,15 +64,15 @@ protected function configure(): void
protected function createComposerJson($modulename, $namespace)
{
$composer_code = $this->twig->render(
'@Modules/'.$this->baseFolder.DIRECTORY_SEPARATOR.'composer.json.twig',
'@Modules' . $this->baseFolder . DIRECTORY_SEPARATOR . 'composer.json.twig',
[
'module_name' => $modulename,
'test' => $this->testGeneration,
'module_name' => $modulename,
'test' => $this->testGeneration,
'name_space_psr4' => str_replace('\\', '\\\\', $namespace),
]
);
$this->filesystem->dumpFile(
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR .
'composer.json',
$composer_code
);
Expand All @@ -78,31 +81,31 @@ protected function createComposerJson($modulename, $namespace)
protected function createConfig($modulename)
{
$service_code = $this->twig->render(
'@Modules/'.$this->baseControllerFolder.DIRECTORY_SEPARATOR.'services.yml.twig'
'@Modules' . $this->baseControllerFolder . DIRECTORY_SEPARATOR . 'services.yml.twig'
);
$module_config_path =
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.'config'.
DIRECTORY_SEPARATOR.'admin';
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR . 'config' .
DIRECTORY_SEPARATOR . 'admin';
$this->filesystem->dumpFile(
$module_config_path.DIRECTORY_SEPARATOR.'service.yml',
$module_config_path . DIRECTORY_SEPARATOR . 'service.yml',
$service_code
);
}

protected function createController($modulename, $namespace)
{
$controller_code = $this->twig->render(
'@Modules/'.$this->baseControllerFolder.DIRECTORY_SEPARATOR.'configuration.php.twig',
'@Modules' . $this->baseControllerFolder . DIRECTORY_SEPARATOR . 'configuration.php.twig',
[
'class_name' => 'ConfigurationController',
'class_name' => 'ConfigurationController',
'module_name' => $modulename,
'name_space' => $namespace,
'name_space' => $namespace,
]
);

$this->filesystem->dumpFile(
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.'src'.
DIRECTORY_SEPARATOR.'Controller'.DIRECTORY_SEPARATOR.
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR .
'ConfigurationController.php',
$controller_code
);
Expand All @@ -111,54 +114,53 @@ protected function createController($modulename, $namespace)
protected function createControllerForm($modulename, $namespace)
{
$controller_code = $this->twig->render(
'@Modules/'.$this->baseControllerFolder.DIRECTORY_SEPARATOR.'form.php.twig',
'@Modules' . $this->baseControllerFolder . DIRECTORY_SEPARATOR . 'form.php.twig',
[
'class_name' => 'ConfigurationType',
'class_name' => 'ConfigurationType',
'module_name' => $modulename,
'name_space' => $namespace,
'name_space' => $namespace,
]
);

$this->filesystem->dumpFile(
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.'src'.
DIRECTORY_SEPARATOR.'Form'.DIRECTORY_SEPARATOR.'Type'.
DIRECTORY_SEPARATOR.'ConfigurationType.php',
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . 'Form' . DIRECTORY_SEPARATOR . 'Type' .
DIRECTORY_SEPARATOR . 'ConfigurationType.php',
$controller_code
);
}

protected function createControllerTemplate($modulename, $templatename)
{
$module_view_path =
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.'views'.
DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.'admin'.
DIRECTORY_SEPARATOR.'controller';
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR . 'views' .
DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'admin' .
DIRECTORY_SEPARATOR . 'controller';
$this->filesystem->mkdir($module_view_path);
$this->filesystem->copy(
_PS_MODULE_DIR_.$this->baseControllerFolder.DIRECTORY_SEPARATOR.
_PS_MODULE_DIR_ . $this->baseControllerFolder . DIRECTORY_SEPARATOR .
'template_controller.twig',
$module_view_path.DIRECTORY_SEPARATOR.'admin_configuration.html.twig'
$module_view_path . DIRECTORY_SEPARATOR . 'admin_configuration.html.twig'
);
}

protected function createFrontController($module_name, $front_controller_name)
{
$front_controller_folder =
$this->getModuleDirectory($this->moduleName).DIRECTORY_SEPARATOR.
'controllers'.DIRECTORY_SEPARATOR.'front';
$this->getModuleDirectory($this->moduleName) . DIRECTORY_SEPARATOR .
'controllers' . DIRECTORY_SEPARATOR . 'front';

$this->filesystem->mkdir($front_controller_folder);

$model_front_file_name = $this->baseControllerFolder.DIRECTORY_SEPARATOR.
$model_front_file_name = $this->baseControllerFolder . DIRECTORY_SEPARATOR .
'front_controller.php.twig';
$front_controller_code = $this->twig->render
('@Modules/'.$model_front_file_name, [
'module_name' => $module_name,
$front_controller_code = $this->twig->render('@Modules' . $model_front_file_name, [
'module_name' => $module_name,
'front_controller_name' => $front_controller_name,
]);

$front_filename =
$front_controller_folder.DIRECTORY_SEPARATOR.$front_controller_name.
$front_controller_folder . DIRECTORY_SEPARATOR . $front_controller_name .
'.php';
$this->filesystem->dumpFile($front_filename, $front_controller_code);
}
Expand All @@ -168,36 +170,36 @@ protected function createFrontControllerJavascript(
$front_controller_name
) {
$js_folder =
$this->getModuleDirectory($this->moduleName).DIRECTORY_SEPARATOR.'views'.
DIRECTORY_SEPARATOR.'js';
$this->getModuleDirectory($this->moduleName) . DIRECTORY_SEPARATOR . 'views' .
DIRECTORY_SEPARATOR . 'js';
$this->filesystem->mkdir($js_folder);

$js_front_controller_code = $this->twig->render(
'@Modules/'.$this->baseViewFolder.DIRECTORY_SEPARATOR.'js'
.DIRECTORY_SEPARATOR.
'@Modules' . $this->baseViewFolder . DIRECTORY_SEPARATOR . 'js'
. DIRECTORY_SEPARATOR .
'front_controller.js.twig',
[
'module_name' => $module_name,
'module_name' => $module_name,
'front_controller_name' => $front_controller_name,
]
);
$this->filesystem->dumpFile(
$js_folder.DIRECTORY_SEPARATOR.$front_controller_name.'.js',
$js_folder . DIRECTORY_SEPARATOR . $front_controller_name . '.js',
$js_front_controller_code
);
}

protected function createMain($modulename)
{
$controller_code = $this->twig->render(
'@Modules/'.$this->baseFolder.DIRECTORY_SEPARATOR.'main.php.twig',
'@Modules' . $this->baseFolder . DIRECTORY_SEPARATOR . 'main.php.twig',
[
'module_name' => $modulename,
]
);

$this->filesystem->dumpFile(
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.$modulename.
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR . $modulename .
'.php',
$controller_code
);
Expand All @@ -211,41 +213,42 @@ protected function createModule($modulename)
protected function createRoute($modulename, $namespace)
{
$module_route_path =
$this->getModuleDirectory($modulename).DIRECTORY_SEPARATOR.'config';
$this->getModuleDirectory($modulename) . DIRECTORY_SEPARATOR . 'config';
if ($this->filesystem->exists($module_route_path) === false) {
$this->filesystem->mkdir($module_route_path);
}
$route_code = $this->twig->render(
'@Modules/'.$this->baseControllerFolder.DIRECTORY_SEPARATOR.'routes.yml.twig',
'@Modules' . $this->baseControllerFolder . DIRECTORY_SEPARATOR . 'routes.yml.twig',
[
'module_name' => $modulename,
'name_space' => $namespace,
'name_space' => $namespace,
]
);
$this->filesystem->dumpFile(
$module_route_path.DIRECTORY_SEPARATOR.'routes.yml',
$module_route_path . DIRECTORY_SEPARATOR . 'routes.yml',
$route_code
);
}

protected function createTest($modulename)
{
$module_dir = $this->getModuleDirectory($modulename);
$test_dir = $module_dir.DIRECTORY_SEPARATOR.'test';
$test_dir = $module_dir . DIRECTORY_SEPARATOR . 'test';
$this->filesystem->mkdir($test_dir);
$this->filesystem->copy(
_PS_MODULE_DIR_.$this->baseTestFolder.DIRECTORY_SEPARATOR.'bootstrap.php.twig',
$test_dir.DIRECTORY_SEPARATOR.'bootstrap.php'
_PS_MODULE_DIR_ . $this->baseTestFolder . DIRECTORY_SEPARATOR . 'bootstrap.php.twig',
$test_dir . DIRECTORY_SEPARATOR . 'bootstrap.php'
);
$this->filesystem->copy(
_PS_MODULE_DIR_. $this->baseTestFolder.DIRECTORY_SEPARATOR.'phpunit.xml.twig',
$module_dir.DIRECTORY_SEPARATOR.'phpunit.xml'
_PS_MODULE_DIR_ . $this->baseTestFolder . DIRECTORY_SEPARATOR . 'phpunit.xml.twig',
$module_dir . DIRECTORY_SEPARATOR . 'phpunit.xml'
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void|null
*/
protected function execute(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -312,11 +315,12 @@ protected function execute(InputInterface $input, OutputInterface $output)

/**
* @param string $modulename
*
* @return string
*/
protected function getModuleDirectory($modulename): string
{
return _PS_MODULE_DIR_.$modulename;
return _PS_MODULE_DIR_ . $modulename;
}

protected function interact(InputInterface $input, OutputInterface $output)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends '@PrestaShop/Admin/layout.html.twig' %}
{#TODO: Edit#}
{% set layoutTitle = 'xxxxxx'|trans({}, 'Admin.Modules.') %}
{% set layoutTitle = 'xxxxxx'|trans({}, 'Modules.xxxx.Admin') %}

{% block content %}
{{ form_start(form) }}
Expand All @@ -10,12 +10,12 @@
<div class="card">
<div class="card-header">
{#TODO: Edit#}
{{ 'Configuration'|trans({}, 'Admin.Modules.xxxxx') }}
{{ 'Configuration'|trans({}, 'Modules.xxxx.Admin') }}
</div>
<div class="card-body">
<div class="form-group row">
{#TODO: Edit#}
<div class="form-control-label">{{ 'xxxxxx'|trans({}, 'Admin.Modules.xxxxxxx') }}</div>
<div class="form-control-label">{{ 'xxxxxx'|trans({}, 'Modules.xxxx.Admin') }}</div>
<div class="col-sm-4">
{{ form_errors(form.CONFNAME) }}
{{ form_widget(form.CONFNAME) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ class {{ module_name|capitalize }} extends Module
);
}
public function isUsingNewTranslationSystem()
{
return true;
}
}

0 comments on commit 4cf9135

Please sign in to comment.