A. What is plugins in EC-CUBE?
- is a package( include folders, files ) that adds a specific feature to EC-CUBE core.
1. Plugin vs module vs add-in, add-on, extension
- same same idea.
2. Plugin EC-CUBE vs bundle of Symfony
- A bundle is similar to a plugin in other software, but even better.
- The core features of Symfony framework are implemented with bundles.
- Plugin extend and inheritance features of EC-CUBE.
B. Why do we need plugins?
- Not change EC-CUBE core code.
- reduce risk, reduce big problem, loose control.
- can update new version of EC-CUBE.
- Can enable or disable plugin but not affect your business.
- Can update & compatible with other plugins.
C. When do not we need plugins?
- Change Symfony workflow.
- Change EC-CUBE workflow.
- Change theme of site.
D. How about plugin ?
Position
EC-CUBE3n Root Directory
├── app
│ ├── cache
│ ├── config
│ ├── console
│ ├── log
│ ├── Plugin ★Plugins Folder
│ │ ├── [plugin code] ☆root folder of the plugin
I. Workflow
1. when you install a plugin:
- by GUI
- Archive file to template folder
- Validation plugin
- Moving plugin into folder app/Plugin/
- Insert information into table Plugin
- Call function {install} which was define in folder [plugin code]/PluginManager.php
- Create database for plugin if had defined in folder [plugin code]/Entity
- by command
- Validation plugin
- Insert information into table Plugin
- Call function {install} which was define in folder [plugin code]/PluginManager.php
- Create database for plugin if had defined in folder [plugin code]/Entity
2. when you enable a plugin:
- GUI & command
- Change flag to enable in table Plugin
- Clear cache and rebuild Schema of database in folder app/Proxy/
3. when you disable a plugin:
- GUI & command
- Change flag to disable in table Plugin
- Clear cache and rebuild Schema of database in folder app/Proxy/
4. when you uninstall a plugin:
- GUI & command
- Remove out table Plugin
- Remove folder in app/Plugin/[plugin code]
- Clear cache and rebuild Schema of database in folder app/Proxy/
5. when you update a plugin:
- GUI & command
- update information table Plugin
- Replace folder in app/Plugin/[plugin code]
- Clear cache and rebuild Schema of database in folder app/Proxy/
6. when running:
- Load all Symfony and Bundles
- Load EC-CUBE core
- Listen feedback of plugin with each event
- If plugin have register interactive with the event
- Call function handle event of the event
- Finish EC-CUBE core
- Finish Symfony and Bundle
II. Elements specification
Require elements
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ★Root folder of specification plugin
│ │ │ ├── config.yml ★Declare & information of plugin
│ │ │ ├── PluginManager.php ★Declare & information of plugin
- config.yml
# Required elements
name: [plugin name]
code: [plugin code]
version: 1.0.0
# Optional elements with PSR-4
- PluginManager.php
class PluginManager extends AbstractPluginManager
{
/**
* @param array $config
* @param Application $app
* will be called when install plugin
*/
public function install($config, $app)
{
}
/**
* @param array $config
* @param Application $app
* will be called when uninstall plugin
*/
public function uninstall($config, $app)
{
}
/**
* @param array $config
* @param Application $app
* will be called when enable plugin
*/
public function enable($config, $app)
{
}
/**
* @param array $config
* @param Application $app
* will be called when disable plugin
*/
public function disable($config, $app)
{
}
/**
* @param array $config
* @param Application $app
* will be called when update plugin
*/
public function update($config, $app)
{
}
}
Optional elements
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ☆Root folder of specification plugin
│ │ │ ├── Entity ★Folder contain all entity inside
│ │ │ │ ├── [Name].php ★Declare affect to table
│ │ │ │ ├── [Name].php
│ │ │ ├── Repository ★Folder contain all repository inside
│ │ │ │ ├── [Name]Repository.php ★Declare repository
│ │ │ │ ├── [Name]Repository.php
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ☆Root folder of specification plugin
│ │ │ ├── Event ★Folder contain all class about event
│ │ │ │ ├── [Name].php ★Declare handle class
│ │ │ ├── [Name]Event.php ★Will register listeners for events
class [Name]Event implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'admin.product.edit.initialize' => [['onAdminProductEditInitialize', 10]],
'admin.product.edit.complete' => [['onAdminProductEditComplete', 10]],
'Product/detail.twig' => [['onRenderProductDetail', 10]],
];
}
...
public function onRenderProductDetail(TemplateEvent $event)
{
// implement with $event
}
...
}
- Some events kind were defined in EC-CUBE[will be confirmed]
- System : init & completed
- Route : init
- Controler: init & completed
- Form : form extension
- Template : render
- Specify :
-
Service
- Form Type & Form Extension
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ☆Root folder of specification plugin
│ │ │ ├── Form ★Folder contain all class about event
│ │ │ │ ├── [Type,Extension] ★Folder contain form
│ │ │ │ │ ├── [Name].php ★Declare form
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ☆Root folder of specification plugin
│ │ │ ├── Resource ★Folder contain all class about event
│ │ │ │ ├── locale ★Folder contain form
│ │ │ │ │ ├── [Name].ja.php ★Japanese
│ │ │ │ │ ├── [Name].en.php ★English
│ │ │ │ ├── template ★Folder contain form
│ │ │ │ │ ├── admin ★Folder contain template for admin
│ │ │ │ │ │ ├── [Name].php
│ │ │ │ │ ├── default ★Folder contain template for front
│ │ │ │ │ │ ├── [Name].php
│ │ │ │ ├── asset ★Folder contain resource
│ │ │ │ │ ├── [html,js,css,image..]
│ │ │ │ ├─- config
│ │ │ │ │ ├── services.yml ★Contain any params, .....
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ☆Root folder of specification plugin
│ │ │ ├── Tests ★Folder contain all class about event
│ │ │ │ ├── [Web/...] ★Folder contain testsuite
│ │ │ │ │ ├── [Name]Test.php ★contain testcase
│ │ │ │ ├── bootstrap.php ★Setup information for phpUnit
- Navigation
EC-CUBE3n Root Directory
├── app
│ ├── Plugin ☆Folder contain all plugins inside
│ │ ├── [plugin code] ☆Root folder of specification plugin
│ │ │ ├── Nav.php ★Specify position in menu
class Nav implements EccubeNav
{
public static function getNav()
{
return [
'product' => [
'id' => [unique name for menu],
'name' => [Menu name],
'url' => [route path]
]
];
}
}