Skip to content

Commit

Permalink
Added Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickaël Andrieu committed Jul 8, 2019
1 parent a7431b0 commit aab90d6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
7 changes: 6 additions & 1 deletion doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require_once __DIR__ . '/vendor/autoload.php';

use FOP\Doctrine\Menu\TabManager;

class Doctrine extends Module
{
/**
Expand Down Expand Up @@ -33,7 +35,10 @@ public function __construct()
public function install()
{
parent::install();


TabManager::addTab('AdminDoctrine', 'Doctrine Menu', 'doctrine', 'AdminTools', 'storage');
TabManager::addTab('AdminDoctrineFormClass', 'Controller exemple', 'doctrine', 'AdminDoctrine');
TabManager::addTab('AdminDoctrineGridClass', 'Grid exemple', 'doctrine', 'AdminDoctrine');
Db::getInstance()->execute(
'CREATE TABLE ' . _DB_PREFIX_ . 'demo_entity (id INT AUTO_INCREMENT NOT NULL, isbn VARCHAR(13) NOT NULL, expiration_date DATE NOT NULL, alternative_description LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
final class FormController extends FrameworkBundleAdminController
{
/**
* @Route("/form", methods={"GET", "POST"}, name="doctrine_demo_form")
* @Route("/form", methods={"GET", "POST"}, name="doctrine_demo_form", defaults={
* "_legacy_controller": "AdminDoctrineFormClass",
* "_legacy_link": "AdminDoctrineFormClass"
* })
*/
public function renderForm(Request $request)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/GridController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
final class GridController extends FrameworkBundleAdminController
{
/**
* @Route("/grid", methods={"GET", "POST"}, name="doctrine_demo_grid")
* @Route("/grid", methods={"GET", "POST"}, name="doctrine_demo_grid", defaults={
* "_legacy_controller": "AdminDoctrineGridClass",
* "_legacy_link": "AdminDoctrineGridClass"
* })
*
* @param DemoFilters $filters
* @param GridFactoryInterface $gridFactory
*
* @return Response
*/
Expand Down
45 changes: 45 additions & 0 deletions src/Menu/TabManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace FOP\Doctrine\Menu;

use Tab;
use Language;

/**
* Allows to insert a menu in PrestaShop Back Office
*/
final class TabManager
{
/**
* @param $className
* @param $tabName
* @param $moduleName
* @param $parentClassName
* @param $icon
*
* @return Tab
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public static function addTab($className, $tabName, $moduleName, $parentClassName, $icon = null)
{
$tab = new Tab();
$tab->active = 1;
$tab->class_name = $className;
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = $tabName;
}

if (!is_null($icon)) {
$tab->icon = $icon;
}

$tab->id_parent = (int) Tab::getIdFromClassName($parentClassName);
$tab->module = $moduleName;
$tab->add();

return $tab;
}
}

0 comments on commit aab90d6

Please sign in to comment.