Skip to content
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

Update modules after changes from the core, use two different templat… #1

Merged
merged 20 commits into from Jul 4, 2019
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,9 @@
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}]
]
}
@@ -1 +1,6 @@
vendor
node_modules
mails/*
!mails/layouts
!mails/themes
.DS_Store
@@ -0,0 +1 @@
@import "~bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css";
@@ -1,4 +1,3 @@
<?php
/**
* 2007-2019 PrestaShop SA and Contributors
*
@@ -24,19 +23,14 @@
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\Module\ExampleModuleMailtheme\Controller\Admin;
const $ = require('jquery');
const colorpicker = require('bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min');

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use Symfony\Component\HttpFoundation\Request;
//This component comes from PrestaShop core, this path is relative so you need to build assets with your modules
//installed in a PrestaShop project
import TranslatableInput from '../../../../admin-dev/themes/new-theme/js/components/translatable-input';
This conversation was marked as resolved by PierreRambaud

This comment has been minimized.

Copy link
@PierreRambaud

PierreRambaud Jul 1, 2019

Is it working when admin directory is not admin-dev?

This comment has been minimized.

Copy link
@PierreRambaud

PierreRambaud Jul 1, 2019

I think you need to find a global variable from Prestashop Admin to retrieve the path 🤔

This comment has been minimized.

Copy link
@jolelievre

jolelievre Jul 1, 2019

Author Contributor

I'm not sur such variable exist in JavaScript 🤔
Besides this is only used during development since is then compiled and only the assets are used in the module. So I figured this was ok (I added the comment to clarify this though)
By the way, our admin core js files work the same way (although less problem for them since they already are in the admin-dev folder)

This comment has been minimized.

Copy link
@jolelievre

jolelievre Jul 1, 2019

Author Contributor

ps_linklist (the only other module using core javascript) only worked with the same principle
But I agree with you we should probable have a way to define the admin folder in javascript, the thing is you would have to store it in a js file, and how do you include it if you don't know its folder?
The very best solution would be to externalize our javascript code in a library so that modules can integrate it, this no matter where the admin folder is AND you don't even need to develop your module inside a PrestaShop instance

This comment has been minimized.

Copy link
@PierreRambaud

PierreRambaud Jul 1, 2019

You're right, I'm not awake ^^'
I'm in favor of making our code library external. It will be harder and harder to use in the future :/


class ExampleModuleMailthemeController extends FrameworkBundleAdminController
{
public function indexAction(Request $request)
{
return $this->render('@Modules/example_module_mailtheme/views/templates/admin/index.html.twig', [
'enableSidebar' => true,
//'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
]);
}
}
$(document).ready(function() {
$('.color-picker').colorpicker();
new TranslatableInput();
});
@@ -20,7 +20,8 @@
"exclude-from-classmap": []
},
"config": {
"preferred-install": "dist"
"preferred-install": "dist",
"prepend-autoloader": false
},
"type": "prestashop-module"
}
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>example_module_mailtheme</name>
<displayName><![CDATA[Example Module Mail Theme]]></displayName>
<displayName><![CDATA[Example Module Email Theme]]></displayName>
<version><![CDATA[1.0.0]]></version>
<description><![CDATA[Example module to add a Mail theme to PrestaShop.]]></description>
<description><![CDATA[Example module to deal with an Email theme in PrestaShop.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[]]></tab>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
</module>
@@ -2,6 +2,32 @@ admin_example_module_mailtheme:
path: /example/module_mailtheme
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\ExampleModuleMailtheme\Controller\Admin\ExampleModuleMailthemeController::indexAction'
_controller: 'PrestaShop\Module\ExampleModuleMailtheme\Controller\Admin\DarkThemeController::indexAction'
_legacy_controller: ExampleModuleMailtheme
_legacy_link: ExampleModuleMailtheme
_legacy_link:
- ExampleModuleMailtheme
- ExampleModuleMailtheme:darkTheme

admin_example_module_mailtheme_save_settings:
path: /example/module_mailtheme
methods: [POST]
defaults:
_controller: 'PrestaShop\Module\ExampleModuleMailtheme\Controller\Admin\DarkThemeController::saveSettingsAction'
_legacy_controller: ExampleModuleMailtheme
_legacy_link: ExampleModuleMailtheme:saveDarkThemeSettings

admin_example_module_mailtheme_reset_default_settings:
path: /example/module_mailtheme/reset_default
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\ExampleModuleMailtheme\Controller\Admin\DarkThemeController::resetDefaultSettingsAction'
_legacy_controller: ExampleModuleMailtheme
_legacy_link: ExampleModuleMailtheme:resetDarkThemeDefaultSettings

admin_example_module_mailtheme_generate:
path: /example/module_mailtheme/generate
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\ExampleModuleMailtheme\Controller\Admin\DarkThemeController::generateAction'
_legacy_controller: ExampleModuleMailtheme
_legacy_link: ExampleModuleMailtheme:generateDarkTheme
@@ -0,0 +1,18 @@
services:
_defaults:
public: true

prestashop.module.example_module_mailtheme.dark_theme_settings:
class: PrestaShop\Module\ExampleModuleMailtheme\DarkThemeSettings
arguments:
- '@prestashop.adapter.legacy.configuration'
- "@=service('prestashop.adapter.legacy.context').getLanguages()"

# We need to define this form type manually (no form.type.translatable.aware parent) and check the translator
# existence because in legacy context the service is not available
form.type.dark_theme_settings:
class: PrestaShop\Module\ExampleModuleMailtheme\Form\DarkThemeSettingsType
public: true
parent: 'form.type.translatable.aware'
tags:
- { name: form.type }
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.