Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
luigimassa committed Sep 22, 2024
1 parent b1dcb56 commit 62920e1
Show file tree
Hide file tree
Showing 30 changed files with 101 additions and 92 deletions.
33 changes: 27 additions & 6 deletions config/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,46 @@ services:
tags:
- { name: fop.console.module_generator.module_generator }

fop.console.module_generator.module.phpunit_file:
fop.console.module_generator.module.front_phpunit_file:
public: true
parent: fop.console.module_generator.file_generator
class: FOP\Console\Generator\StaticFileGenerator
calls:
- [ setTemplateName, [ 'phpunit.xml.twig' ] ]
- [ setTemplateName, [ 'phpunit.front.xml.twig' ] ]
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%' ] ]
- [ setFileNameModule,[ 'phpunit.xml.dit' ] ]
- [ setFileNameModule,[ 'phpunit.xml.front' ] ]
tags:
- { name: fop.console.module_generator.module_generator }
fop.console.module_generator.module.admin_phpunit_file:
public: true
parent: fop.console.module_generator.file_generator
class: FOP\Console\Generator\StaticFileGenerator
calls:
- [ setTemplateName, [ 'phpunit.admin.xml.twig' ] ]
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%' ] ]
- [ setFileNameModule,[ 'phpunit.xml.admin' ] ]
tags:
- { name: fop.console.module_generator.module_generator }

fop.console.module_generator.module.test_bootstrap_admin_file:
public: true
parent: fop.console.module_generator.file_generator
class: FOP\Console\Generator\StaticFileGenerator
calls:
- [ setTemplateName, [ 'bootstrap.admin.php.twig' ] ]
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%' ] ]
- [ setFileNameModule,[ '/tests/admin/bootstrap.php' ] ]
tags:
- { name: fop.console.module_generator.module_generator }

fop.console.module_generator.module.test_bootstrap_file:
fop.console.module_generator.module.test_bootstrap_front_file:
public: true
parent: fop.console.module_generator.file_generator
class: FOP\Console\Generator\StaticFileGenerator
calls:
- [ setTemplateName, [ 'bootstrap.php.twig' ] ]
- [ setTemplateName, [ 'bootstrap.front.php.twig' ] ]
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%' ] ]
- [ setFileNameModule,[ '/tests/bootstrap.php' ] ]
- [ setFileNameModule,[ '/tests/front/bootstrap.php' ] ]
tags:
- { name: fop.console.module_generator.module_generator }

Expand Down
4 changes: 3 additions & 1 deletion config/module_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
- [ setTemplateName, [ 'configuration_form.php.twig' ] ]
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%/configuration' ] ]
- [ setClassFolderName,[ 'src/Form/' ] ]
- [ setFileNameModule,[ 'ConfigurationForm.php' ] ]
- [ setFileNameModule,[ 'ConfigurationFormType.php' ] ]
tags:
- { name: fop.console.module_generator.configuration_generator }

Expand All @@ -45,6 +45,8 @@ services:
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%/configuration' ] ]
- [ setClassFolderName,[ 'src/Provider/' ] ]
- [ setFileNameModule,[ 'ConfigurationTextFormDataProvider.php' ] ]
tags:
- { name: fop.console.module_generator.configuration_generator }

fop.console.module_generator.configuration.controller_twig_file:
public: true
Expand Down
2 changes: 1 addition & 1 deletion config/module_front_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- [ setTemplateName, [ 'front_controllerajax.php.twig' ] ]
- [ setTemplatesBaseFolder,[ '%templates_module_generator_base_path%/front_controller' ] ]
- [ setFileNameModule,[ '.php' ] ]
- [ setClassFolderName,[ 'controller/front/' ] ]
- [ setClassFolderName,[ 'controllers/front/' ] ]
tags:
- { name: fop.console.module_generator.front_controller_generator }

Expand Down
14 changes: 7 additions & 7 deletions src/Commands/Group/GroupTransferCustomers.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ private function generateChoiceQuestion(
$optionSeletedID = (int) str_replace($questionsKeyPrefix, '', $optionSeletedKey);

switch ($type) {
case 'groups':
$groupName = $this->getGroupName($optionSeletedID);
$output->writeln('<info>You have just selected: ' . $groupName . '</info>');
break;
case 'actions':
$output->writeln('<info>You have just selected: ' . $questionOptions[$optionSeletedKey] . '</info>');
break;
case 'groups':
$groupName = $this->getGroupName($optionSeletedID);
$output->writeln('<info>You have just selected: ' . $groupName . '</info>');
break;
case 'actions':
$output->writeln('<info>You have just selected: ' . $questionOptions[$optionSeletedKey] . '</info>');
break;
}

return $optionSeletedID;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Module/ModuleGenerateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
return;
}

$this->configGeneration->nameSpace = $helper->ask($input, $output, new Question('Name space? : '));
$this->configGeneration->nameSpace = $helper->ask($input, $output, new Question('Main name space? : '));
$this->configGeneration->serviceNameSpace =
$helper->ask($input, $output, new Question('Service name space? (example mymodule.service...): '));
$this->configGeneration->className =
Expand Down
10 changes: 8 additions & 2 deletions src/Commands/Module/ModuleGenerateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function interact(InputInterface $input, OutputInterface $output)

$this->moduleName = $helper->ask($input, $output, $ask_module_name);

if (!file_exists(_PS_MODULE_DIR_ . $this->moduleName)) {
if (!file_exists(_PS_MODULE_DIR_.$this->moduleName)) {
$output->writeln('Module does not exist');

return;
Expand All @@ -81,13 +81,19 @@ protected function interact(InputInterface $input, OutputInterface $output)
$this->configGeneration->nameSpace = $helper->ask(
$input,
$output,
new Question('Name space? : ')
new Question('Main name space? : ')
);
$this->configGeneration->className = $helper->ask(
$input,
$output,
new Question('Controller name? (eg: ExampleController) : ')
);

if (strpos($this->configGeneration->className, 'Controller') === false) {
$this->configGeneration->className .= 'Controller';
}


$this->configGeneration->serviceName = strtolower($this->configGeneration->className);
}
}
2 changes: 1 addition & 1 deletion src/Commands/Module/ModuleGenerateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setGeneratorServices(iterable $services)
protected function configure(): void
{
$this->setName('fop:module:generate:form')
->setDescription('Scaffold form for backoffice');
->setDescription('Add form type in Prestashop module');
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Module/ModuleGenerateFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setGeneratorServices(iterable $services)
protected function configure(): void
{
$this->setName('fop:module:generate:front-controller')
->setDescription('Add a grid to a Prestashop module')
->setDescription('Add front controller in Prestashop module')
->addOption('add-ajax', null, null, 'Add ajax to the grid');
}

Expand Down
1 change: 0 additions & 1 deletion src/Generator/StaticFileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ protected function getModuleFolder(): string
{
return $this->getModuleDirectory().DIRECTORY_SEPARATOR;
}

}
1 change: 0 additions & 1 deletion src/Generator/YamlFileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class YamlFileGenerator extends FileGenerator
{

protected function getModuleFolder(): string
{
return $this->getModuleDirectory()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$_SERVER['REQUEST_METHOD'] = 'POST';
define('_PS_ROOT_DIR_', __DIR__ . '/../../..');
define('_PS_ROOT_DIR_', __DIR__ . '/../../../..');
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', _PS_ROOT_DIR_.ADMIN_FOLDER_NAME);
}
Expand All @@ -9,14 +9,12 @@ if (!defined('PS_ADMIN_DIR')) {
define('PS_ADMIN_DIR', _PS_ADMIN_DIR_);
}
require_once __DIR__.'/../../../config/config.inc.php';
require_once __DIR__.'/../../../init.php';
require_once _PS_CONFIG_DIR_ . 'autoload.php';
require_once __DIR__.'/../../../../config/config.inc.php';
require_once __DIR__.'/../../../../init.php';
## admin
require_once _PS_ROOT_DIR_.'/app/AppKernel.php';
$kernel = new \AppKernel(_PS_ENV_, _PS_DEBUG_);
$kernel->boot();
//define('_NEW_COOKIE_KEY_', PhpEncryption::createNewRandomKey());
require_once _PS_VENDOR_DIR_ . '/autoload.php';
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
<?php
$_SERVER['REQUEST_METHOD'] = 'POST';
define('_PS_ROOT_DIR_', __DIR__ . '/../../..');
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', _PS_ROOT_DIR_.ADMIN_FOLDER_NAME);
}
require dirname(__FILE__).'/../../../../config/config.inc.php';
require_once __DIR__.'/../../../../init.php';
if (!defined('PS_ADMIN_DIR')) {
define('PS_ADMIN_DIR', _PS_ADMIN_DIR_);
}
require_once __DIR__.'/../../../config/config.inc.php';
require_once __DIR__.'/../../../init.php';
require_once _PS_CONFIG_DIR_ . 'autoload.php';
## admin
require_once _PS_ROOT_DIR_.'/app/AppKernel.php';
$kernel = new \AppKernel(_PS_ENV_, _PS_DEBUG_);
$kernel->boot();
//define('_NEW_COOKIE_KEY_', PhpEncryption::createNewRandomKey());
require_once _PS_VENDOR_DIR_ . '/autoload.php';
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"autoload-dev": {
"psr-4": {
"{{ nameSpace }}\\Tests\\": "tests/"
"{{ nameSpace }}\\Tests\\Admin\\": "tests/admin/",
"{{ nameSpace }}\\Tests\\Front\\": "tests/front/"
},
"config": {
"prepend-autoloader": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

}

$form => $textForm->createView();
$textForm = $textForm->createView();

return $this->render(
'@Modules/{{moduleName}}/views/templates/admin/controller/{{serviceName}}_configuration_view.html.twig',
[
'form' => $form,
'form' => $textForm,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
services:
{{ serviceNameSpace }}.form.type.{{ serviceName }}_text:
class: {{ nameSpace }}\Form\{{className}}ConfigurationFormType
parent: 'form.type.translatable.aware'
public: true
calls:
- [ setOrderStatusChoicesProvider,[ '@prestashop.core.form.choice_provider.order_state_by_id' ] ]
tags:
- { name: form.type }

{{ serviceNameSpace }}.data.configuration.{{ serviceName }}_text_data_configuration:
class: {{ nameSpace }}\DataConfiguration\{{className}}TextDataConfiguration
class: {{ nameSpace }}\Configuration\{{className}}TextDataConfiguration
arguments: [ '@prestashop.adapter.legacy.configuration' ]

{{ serviceNameSpace }}.provider.{{serviceName}}_configuration_text_form_data_provider:
class: {{ nameSpace }}\Provider\{{className}}ConfigurationTextFormDataProvider
arguments:
- '@{{ serviceNameSpace }}.data.configuration.{{serviceName}}_text_data_configuration'
-

{{nameSpace}}\Form\{{className}}ConfigurationFormType:
class: {{nameSpace}}\Form\{{className}}ConfigurationFormType
arguments:
- "@translator"
- "@=service('prestashop.adapter.legacy.context').getLanguages()"
tags:
- { name: form.type }

{{ serviceNameSpace }}.handler.{{ serviceName }}_configuration_text_form_data_handler:
class: 'PrestaShop\PrestaShop\Core\Form\Handler'
public: true
arguments:
- '@form.factory'
- '@prestashop.core.hook.dispatcher'
- '@{{serviceNameSpace}}.provider.{{ serviceName }}_configuration_text_form_data_provider'
- '{{nameSpace}}\Form\{{className}}FormType'
- '{{nameSpace}}\Form\{{className}}ConfigurationFormType'
- '{{ className }}'
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace {{nameSpace}}\Form;
use {{nameSpace}}\DataConfiguration\{{ className }}TextDataConfiguration;
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface;
use {{nameSpace}}\Configuration\{{ className }}TextDataConfiguration;
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -16,8 +15,8 @@ class {{className}}ConfigurationFormType extends TranslatorAwareType
{
$builder
->add({{className}}TextDataConfiguration::CONFIGNAME, TextType::class, [
'label' => $this->trans('xxxx',[], 'Modules.{{ moduleName|capitalize }}.Admin'),
'help' => $this->trans('xxxxx',[],'Modules.{{ moduleName|capitalize }}.Admin'),
'label' => $this->trans('xxxx', 'Modules.{{ moduleName|capitalize }}.Admin', []),
'help' => $this->trans('xxxxx', 'Modules.{{ moduleName|capitalize }}.Admin', []),
]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
namespace {{nameSpace}}\DataConfiguration;
namespace {{nameSpace}}\Configuration;
use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface;
Expand All @@ -25,14 +25,14 @@ class {{ className }}TextDataConfiguration implements DataConfigurationInterface
{
$return = [];
$return[self::CONFIGNAME] = json_decode($this->configuration->get(static::CONFIGNAME), true);
$return[self::CONFIGNAME] = $this->configuration->get(static::CONFIGNAME);
return $return;
}
public function updateConfiguration(array $configuration): array
{
$this->configuration->set(self::CONFIGNAME, json_encode($configuration[self::CONFIGNAME]));
$this->configuration->set(self::CONFIGNAME, $configuration[self::CONFIGNAME]);
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace {{nameSpace}}\Provider;
use {{ nameSpace }}\DataConfiguration\{{ className }}TextDataConfiguration;
use {{ nameSpace }}\Configuration\{{ className }}TextDataConfiguration;
use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface;
class {{ className }}ConfigurationTextFormDataProvider implements FormDataProviderInterface
Expand All @@ -17,15 +17,14 @@ class {{ className }}ConfigurationTextFormDataProvider implements FormDataProvid
$this->configurationTextDataConfiguration = $configurationTextDataConfiguration;
}
public function getData(): array
public function getData()
{
return $this->configurationTextDataConfiguration->getConfiguration();
}
public function setData(array $data): array
public function setData(array $data)
{
return $this->configurationTextDataConfiguration->updateConfiguration($data);
$this->configurationTextDataConfiguration->updateConfiguration($data);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
/**
* <your license here>
*/
namespace {{ nameSpace }}\Controller;
if (!defined('_PS_VERSION_')) {
exit;
}
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class {{ className }} extends TranslatorAwareType
class {{ className }}Type extends TranslatorAwareType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* <your license here>
*/

(function () {

$.ajax({
Expand Down
Loading

0 comments on commit 62920e1

Please sign in to comment.