瀏覽代碼

Refactoring

feature/ticket
Fab 3 年之前
父節點
當前提交
c83e165f8c
共有 36 個文件被更改,包括 920 次插入375 次删除
  1. +170
    -132
      Controller/Admin/AbstractCrudController.php
  2. +42
    -40
      Controller/Admin/DashboardController.php
  3. +11
    -3
      Controller/Admin/UserController.php
  4. +50
    -0
      EventSubscriber/EasyAdminEventSubscriber.php
  5. +1
    -1
      Field/CollectionField.php
  6. +3
    -1
      Field/FileManagerField.php
  7. +4
    -2
      Field/GalleryManagerField.php
  8. +2
    -0
      Field/ImageManagerField.php
  9. +1
    -1
      Form/Type/Crud/FileManagerType.php
  10. +13
    -9
      Form/Type/User/ChangePasswordFormType.php
  11. +22
    -27
      Form/Type/User/ProfileFormType.php
  12. +1
    -0
      Resources/assets/app/adminlte/common/app.common.js
  13. +3
    -0
      Resources/assets/app/adminlte/common/common.js
  14. +24
    -13
      Resources/assets/app/adminlte/common/js/notification.js
  15. +30
    -12
      Resources/assets/app/adminlte/common/scss/_toastr.scss
  16. +0
    -3
      Resources/assets/app/adminlte/field/collection/app.collection.js
  17. +2
    -0
      Resources/assets/app/adminlte/field/filemanager/app.filemanager.js
  18. +2
    -2
      Resources/assets/app/adminlte/index/index.js
  19. +7
    -0
      Resources/config/routes.yaml
  20. +86
    -0
      Resources/translations/admin.fr.yaml
  21. +1
    -0
      Resources/views/adminlte/block/flash_messages.html.twig
  22. +2
    -1
      Resources/views/adminlte/block/menu.html.twig
  23. +6
    -4
      Resources/views/adminlte/crud/_form.html.twig
  24. +6
    -5
      Resources/views/adminlte/crud/action/translatable.html.twig
  25. +1
    -5
      Resources/views/adminlte/crud/edit.html.twig
  26. +114
    -11
      Resources/views/adminlte/crud/form_theme.html.twig
  27. +5
    -5
      Resources/views/adminlte/crud/index.html.twig
  28. +1
    -6
      Resources/views/adminlte/crud/new.html.twig
  29. +9
    -7
      Resources/views/adminlte/crud/paginator.html.twig
  30. +1
    -2
      Resources/views/adminlte/crud/sort.html.twig
  31. +4
    -3
      Resources/views/adminlte/dashboard.html.twig
  32. +20
    -3
      Resources/views/adminlte/layout.html.twig
  33. +1
    -1
      Resources/views/user/change_password.html.twig
  34. +1
    -1
      Resources/views/user/profile.html.twig
  35. +145
    -0
      Translation/TranslatorAdmin.php
  36. +129
    -75
      Twig/TwigExtension.php

+ 170
- 132
Controller/Admin/AbstractCrudController.php 查看文件

@@ -40,6 +40,8 @@ use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Field\CollectionField;
use Lc\SovBundle\Field\GalleryManagerField;
use Lc\SovBundle\Form\Type\Crud\PositionType;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -51,12 +53,19 @@ abstract class AbstractCrudController extends EaAbstractCrudController
protected $session;
protected $request;
protected $em;

public function __construct(SessionInterface $session, RequestStack $request, EntityManager $em)
protected $translatorAdmin;

public function __construct(
SessionInterface $session,
RequestStack $request,
EntityManager $em,
TranslatorAdmin $translatorAdmin
)
{
$this->session = $session;
$this->request = $request;
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
}

public function configureActions(Actions $actions): Actions
@@ -64,68 +73,78 @@ abstract class AbstractCrudController extends EaAbstractCrudController
/* Translatable */
if ($this->isInstanceOf(TranslatableInterface::class)) {
$actions->update(
Crud::PAGE_INDEX,
Action::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
Crud::PAGE_INDEX,
Action::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');

return $action;
}
return $action;
}
);
}

/* Boutons des actions dans les listes */
$actionsArray[Crud::PAGE_INDEX] = [
Action::NEW => [
'icon' => 'plus',
'label' => 'Créer',
'add_class'=>'btn-sm'
],
Action::EDIT => [
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes'=> array('data-toggle'=> 'tooltip', 'title'=> 'Éditer')
],
Action::DELETE => [
'icon' => 'trash',
'dropdown' => true,
],
Action::BATCH_DELETE => [
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
],
Action::NEW => [
'icon' => 'plus',
'label' => $this->translatorAdmin->transAction('create'),
'add_class' => 'btn-sm'
],
Action::EDIT => [
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->translatorAdmin->transAction('edit')
)
],
Action::DELETE => [
'icon' => 'trash',
'dropdown' => true,
'label' => $this->translatorAdmin->transAction('delete')
],
Action::BATCH_DELETE => [
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->translatorAdmin->transAction('delete')
],
];

/* Boutons des actions dans l'édition */

$actionSaveAndReturn = [
'add_class' => 'float-right',
'icon' => 'check',
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->translatorAdmin->transAction('save_and_return')
];
$actionIndex = [
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->translatorAdmin->transAction('back_index')
];

$actionsArray[Crud::PAGE_EDIT] = [
Action::SAVE_AND_CONTINUE => [
'class' => 'btn btn-info float-right',
],
Action::DELETE => [
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
],
Action::SAVE_AND_RETURN => $actionSaveAndReturn,
Action::INDEX => $actionIndex,
Action::SAVE_AND_CONTINUE => [
'class' => 'btn btn-info float-right',
'label' => $this->translatorAdmin->transAction('save_and_continue')
],
Action::DELETE => [
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->translatorAdmin->transAction('delete')
],
Action::SAVE_AND_RETURN => $actionSaveAndReturn,
Action::INDEX => $actionIndex,
];

$actionsArray[Crud::PAGE_NEW] = [
Action::SAVE_AND_ADD_ANOTHER => [
'class' => 'btn btn-info float-right',
],
Action::SAVE_AND_RETURN => $actionSaveAndReturn,
Action::INDEX => $actionIndex,
Action::SAVE_AND_ADD_ANOTHER => [
'class' => 'btn btn-info float-right',
'label' => $this->translatorAdmin->transAction('save_and_add_another')
],
Action::SAVE_AND_RETURN => $actionSaveAndReturn,
Action::INDEX => $actionIndex,
];

$actions->add(Crud::PAGE_EDIT, Action::INDEX);
@@ -133,27 +152,35 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$actions->add(Crud::PAGE_NEW, Action::INDEX);

if ($this->isInstanceOf(SortableInterface::class)) {
$sortAction = Action::new('sort', 'Ordonner', 'fa fa-sort')
->linkToCrudAction('sort')
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();
$sortAction = Action::new('sort', $this->translatorAdmin->transAction('sort'), 'fa fa-sort')
->linkToCrudAction('sort')
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();

$actions->add(Crud::PAGE_INDEX, $sortAction);
}


if ($this->isInstanceOf(TreeInterface::class)) {
$indexChildAction = Action::new('index_children', 'Afficher les enfants', 'fa fa-list')
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle'=> 'tooltip', 'title'=> 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');

$backParentAction = Action::new('index_parent', 'Retour au parent', 'fa fa-chevron-left')
->linkToCrudAction(Action::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();
$indexChildAction = Action::new(
'index_children',
$this->translatorAdmin->transAction('index_children'),
'fa fa-list'
)
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');

$backParentAction = Action::new(
'index_parent',
$this->translatorAdmin->transAction('index_parent'),
'fa fa-chevron-left'
)
->linkToCrudAction(Action::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();

$actions->add(Crud::PAGE_INDEX, $backParentAction);
$actions->add(Crud::PAGE_INDEX, $indexChildAction);
@@ -166,35 +193,35 @@ abstract class AbstractCrudController extends EaAbstractCrudController
foreach ($actionsArray as $crudActionName => $actionsStyle) {
foreach ($actionsStyle as $actionName => $button) {
$actions->update(
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}

if (isset($button['class'])) {
$action->setCssClass($button['class']);
}

if (isset($button['icon'])) {
$action->setIcon('fa fa-'.$button['icon']);
}

if (isset($button['label'])) {
$action->setLabel($button['label']);
}

if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}

if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes( $button['html_attributes']);
}

return $action;
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}

if (isset($button['class'])) {
$action->setCssClass($button['class']);
}

if (isset($button['icon'])) {
$action->setIcon('fa fa-' . $button['icon']);
}

if (isset($button['label'])) {
$action->setLabel($button['label']);
}

if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}

if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
}

return $action;
}
);
}
}
@@ -216,7 +243,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$crud = parent::configureCrud($crud);

$this->setMaxResults($crud);
if($this->isInstanceOf(SortableInterface::class)){
if ($this->isInstanceOf(SortableInterface::class)) {
$crud->setDefaultSort(['position' => 'ASC']);
}
return $crud;
@@ -226,14 +253,14 @@ abstract class AbstractCrudController extends EaAbstractCrudController
{
$entityClass = $this->getEntityFqcn();
$paramListMaxResults = 'listMaxResults';
$paramSessionListMaxResults = $entityClass.'-'.$paramListMaxResults;
$paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
$requestListMaxResults = $this->request->getCurrentRequest()->get($paramListMaxResults);

if ($requestListMaxResults) {
$this->session->set($paramSessionListMaxResults, $requestListMaxResults);
}
$maxResults = $this->session->get($paramSessionListMaxResults) ? $this->session->get(
$paramSessionListMaxResults
$paramSessionListMaxResults
) : 30;

$crud->setPaginatorPageSize($maxResults);
@@ -243,24 +270,24 @@ abstract class AbstractCrudController extends EaAbstractCrudController
{
if ($this->isInstanceOf(SortableInterface::class)) {
$seoPanel = [
FormField::addPanel('Seo'),
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
'Affiché dans les résultats de recherche Google'
FormField::addPanel('seo')->setTemplateName('crud/field/generic'),
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
)->hideOnIndex(),
TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
)->hideOnIndex(),
];
}

if ($this->isInstanceOf(DevAliasInterface::class)) {
$confPanel = [
FormField::addPanel('Conf'),
TextField::new('devAlias')->hideOnIndex(),
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
];
}

@@ -282,9 +309,9 @@ abstract class AbstractCrudController extends EaAbstractCrudController

$fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
$filters = $this->get(FilterFactory::class)->create(
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
);
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);
@@ -293,19 +320,18 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$this->get(EntityFactory::class)->processFieldsForAll($entities, $fields);

$sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults()))
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
)
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
)
->getForm();
)
->getForm();

$entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn());

$repository = $entityManager->getRepository($this->getEntityFqcn());

$sortableForm->handleRequest($context->getRequest());
@@ -330,26 +356,26 @@ abstract class AbstractCrudController extends EaAbstractCrudController
}

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::INDEX)
->generateUrl();
$this->addFlash('success', 'Position modifié', array());
->setAction(Action::INDEX)
->generateUrl();
$this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array());

return $this->redirect($url);
}

$responseParameters = $this->configureResponseParameters(
KeyValueStore::new(
[
'pageName' => Crud::PAGE_INDEX,
'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
'entities' => $entities,
'paginator' => $paginator,
'global_actions' => array(),
'batch_actions' => array(),
'filters' => $filters,
'sortable_form' => $sortableForm,
]
)
KeyValueStore::new(
[
'pageName' => Crud::PAGE_INDEX,
'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
'entities' => $entities,
'paginator' => $paginator,
'global_actions' => array(),
'batch_actions' => array(),
'filters' => $filters,
'sortable_form' => $sortableForm,
]
)
);
$responseParameters->set('fields', $this->configureFields('index'));
$event = new AfterCrudActionEvent($context, $responseParameters);
@@ -374,7 +400,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$filters
);

dump(get_defined_vars());
if ($this->isInstanceOf(TreeInterface::class)) {
$entityId = $searchDto->getRequest()->get('entityId');
if ($entityId !== null) {
@@ -401,6 +427,18 @@ abstract class AbstractCrudController extends EaAbstractCrudController
return $queryBuilder;
}

public function edit(AdminContext $context)
{
$response = parent::edit($context);;

// on vide le flash bag si édition en ajax (notification déjà affichée en Javascript)
if ($context->getRequest()->isXmlHttpRequest()) {
$this->session->getFlashBag()->clear();
}

return $response;
}

public function isInstanceOf(string $interfaceName): bool
{
return in_array($interfaceName, class_implements($this->getEntityFqcn()));

+ 42
- 40
Controller/Admin/DashboardController.php 查看文件

@@ -23,14 +23,14 @@ class DashboardController extends AbstractDashboardController
public function configureDashboard(): Dashboard
{
return Dashboard::new()
// the name visible to end users
->setTitle('LA CLIC !')
// you can include HTML contents too (e.g. to link to an image)
->setTitle('<img src="assets/img/laclic.png" width="100px">')
// the path defined in this method is passed to the Twig asset() function
->setFaviconPath('favicon.svg')
// the domain used by default is 'messages'
->setTranslationDomain('lcadmin');
// the name visible to end users
->setTitle('LA CLIC !')
// you can include HTML contents too (e.g. to link to an image)
->setTitle('<img src="assets/img/laclic.png" width="100px">')
// the path defined in this method is passed to the Twig asset() function
->setFaviconPath('favicon.svg')
// the domain used by default is 'messages'
->setTranslationDomain('admin');
}

public function configureAssets(): Assets
@@ -41,6 +41,8 @@ class DashboardController extends AbstractDashboardController
$assets->addWebpackEncoreEntry('adminlte-index');
$assets->addWebpackEncoreEntry('adminlte-form');
$assets->addWebpackEncoreEntry('adminlte-sort');
$assets->addWebpackEncoreEntry('adminlte-field-collection');
$assets->addWebpackEncoreEntry('adminlte-field-filemanager');

return $assets;
}
@@ -51,22 +53,22 @@ class DashboardController extends AbstractDashboardController
// user menu with some menu items already created ("sign out", "exit impersonation", etc.)
// if you prefer to create the user menu from scratch, use: return UserMenu::new()->...
return parent::configureUserMenu($user)
// use the given $user object to get the user name
->setName($user->getName())
// use this method if you don't want to display the name of the user
//->displayUserName(false)
->displayUserAvatar(false)
// you can also pass an email address to use gravatar's service
->setGravatarEmail($user->getEmail())
// use the given $user object to get the user name
->setName($user->getName())
// use this method if you don't want to display the name of the user
//->displayUserName(false)
->displayUserAvatar(false)
// you can also pass an email address to use gravatar's service
->setGravatarEmail($user->getEmail())

// you can use any type of menu item, except submenus
->setMenuItems(
[
//MenuItem::linkToRoute('My Profile', 'fa fa-id-card', '', ['...' => '...']),
MenuItem::linkToLogout('Déconnexion', 'sign-out-alt'),
//MenuItem::linkToLogout('Déconnexion', 'sign-out-alt')
]
);
// you can use any type of menu item, except submenus
->setMenuItems(
[
//MenuItem::linkToRoute('My Profile', 'fa fa-id-card', '', ['...' => '...']),
MenuItem::linkToLogout('Déconnexion', 'sign-out-alt'),
//MenuItem::linkToLogout('Déconnexion', 'sign-out-alt')
]
);
}

public function configureCrud(): Crud
@@ -74,23 +76,23 @@ class DashboardController extends AbstractDashboardController
$crud = Crud::new();

return $crud
->overrideTemplates(
[
'layout' => '@LcSov/adminlte/layout.html.twig',
'main_menu' => '@LcSov/adminlte/block/menu.html.twig',
'crud/index' => '@LcSov/adminlte/crud/index.html.twig',
'crud/paginator' => '@LcSov/adminlte/crud/paginator.html.twig',
'crud/edit' => '@LcSov/adminlte/crud/edit.html.twig',
'crud/new' => '@LcSov/adminlte/crud/new.html.twig',
//'crud/action' => '@LcSov/adminlte/crud/action/action.html.twig',
]
)
->setFormThemes(
[
'@LcSov/adminlte/crud/form_theme.html.twig',
'@FOSCKEditor/Form/ckeditor_widget.html.twig'
]
);
->overrideTemplates(
[
'layout' => '@LcSov/adminlte/layout.html.twig',
'main_menu' => '@LcSov/adminlte/block/menu.html.twig',
'crud/index' => '@LcSov/adminlte/crud/index.html.twig',
'crud/paginator' => '@LcSov/adminlte/crud/paginator.html.twig',
'crud/edit' => '@LcSov/adminlte/crud/edit.html.twig',
'crud/new' => '@LcSov/adminlte/crud/new.html.twig',
'flash_messages' => '@LcSov/adminlte/block/flash_messages.html.twig',
]
)
->setFormThemes(
[
'@LcSov/adminlte/crud/form_theme.html.twig',
'@FOSCKEditor/Form/ckeditor_widget.html.twig'
]
);
}

}

+ 11
- 3
Controller/Admin/UserController.php 查看文件

@@ -2,17 +2,20 @@

namespace Lc\SovBundle\Controller\Admin;

use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Form\Type\User\ChangePasswordFormType;
use Lc\SovBundle\Form\Type\User\ProfileFormType;
use Lc\SovBundle\Model\User\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Translation\TranslatableMessage;

class UserController extends AbstractController
{

protected $em;

public function __construct(EntityManager $em)
@@ -32,12 +35,14 @@ class UserController extends AbstractController

$this->em->update($user);
$this->em->flush();

$this->addFlash('success', new TranslatableMessage('form.account_profile.message.success', [], 'admin'));
}

return $this->render(
'@LcSov/user/profile.html.twig',
[
'form' => $form->createView()
'form' => $form->createView(),
]
);
}
@@ -52,7 +57,7 @@ class UserController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();

$plainPassword = $form->get('plainPassword')->getData();
$plainPassword = $form->get('plain_password')->getData();

// @TODO : créer UserManager
$newPasswordEncoded = $passwordEncoder->encodePassword($user, $plainPassword);
@@ -60,11 +65,14 @@ class UserController extends AbstractController

$this->em->update($user);
$this->em->flush();

$this->addFlash('success', new TranslatableMessage('form.account_password.message.success', [], 'admin'));
}

return $this->render(
'@LcSov/user/change_password.html.twig',
[
'entity_class' => User::class,
'form' => $form->createView()
]
);

+ 50
- 0
EventSubscriber/EasyAdminEventSubscriber.php 查看文件

@@ -0,0 +1,50 @@
<?php

namespace Lc\SovBundle\EventSubscriber;

use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Translation\TranslatableMessage;

class EasyAdminEventSubscriber implements EventSubscriberInterface
{
protected $session ;

public function __construct(SessionInterface $session)
{
$this->session = $session ;
}

public static function getSubscribedEvents(): array
{
return [
AfterEntityPersistedEvent::class => ['flashMessageAfterPersist'],
AfterEntityUpdatedEvent::class => ['flashMessageAfterUpdate'],
AfterEntityDeletedEvent::class => ['flashMessageAfterDelete'],
];
}

public function flashMessageAfterPersist(AfterEntityPersistedEvent $event): void
{
$this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.create', [
'%name%' => (string) $event->getEntityInstance(),
]));
}

public function flashMessageAfterUpdate(AfterEntityUpdatedEvent $event): void
{
$this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.update', [
'%name%' => (string) $event->getEntityInstance(),
]));
}

public function flashMessageAfterDelete(AfterEntityDeletedEvent $event): void
{
$this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.delete', [
'%name%' => (string) $event->getEntityInstance(),
]));
}
}

+ 1
- 1
Field/CollectionField.php 查看文件

@@ -26,7 +26,7 @@ class CollectionField implements FieldInterface
->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/collection.html.twig')
->setFormType(CollectionType::class)
->addWebpackEncoreEntries('adminlte-field-collection')
/*->addWebpackEncoreEntries('adminlte-field-collection')*/
->setFormTypeOption('allow_add', true)
->setFormTypeOption('allow_delete', true)
->setFormTypeOption('entry_options', array('label' => false))

+ 3
- 1
Field/FileManagerField.php 查看文件

@@ -23,7 +23,9 @@ final class FileManagerField implements FieldInterface
->setProperty($propertyName)
->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/file.html.twig')
->addWebpackEncoreEntries('adminlte-field-filemanager')
/*->addWebpackEncoreEntries('adminlte-field-filemanager')*/
->setCustomOption('managerDir', 'file')
->setCustomOption('type', 'file')
->setFormType(FileManagerType::class)
->addCssClass('field-text')
->setCustomOption(self::OPTION_MAX_LENGTH, null)

+ 4
- 2
Field/GalleryManagerField.php 查看文件

@@ -26,14 +26,16 @@ class GalleryManagerField implements FieldInterface
->setTemplatePath('@LcSov/adminlte/crud/field/collection.html.twig')
->setFormType(CollectionType::class)
->addCssClass('field-collection')
->addWebpackEncoreEntries('adminlte-field-collection')
->addWebpackEncoreEntries('adminlte-field-filemanager')
/*->addWebpackEncoreEntries('adminlte-field-collection')
->addWebpackEncoreEntries('adminlte-field-filemanager')*/
->setFormTypeOption('allow_add', true)
->setFormTypeOption('allow_delete', true)
->setFormTypeOption('entry_options', array('label'=> false))
->setFormTypeOption('entry_type', FileManagerType::class)
->setFormTypeOption('attr', array('class'=> 'field-collection-group'))
->setFormTypeOption('row_attr', array('data-sortable'=> true))
->setCustomOption('managerDir', 'image')
->setCustomOption('type', 'image')
->hideOnIndex();

//->setEntryType(FileManagerType::class);

+ 2
- 0
Field/ImageManagerField.php 查看文件

@@ -25,6 +25,8 @@ final class ImageManagerField implements FieldInterface
->setTemplatePath('@LcSov/adminlte/crud/field/image.html.twig')
->addWebpackEncoreEntries('adminlte-field-filemanager')
->setFormType(FileManagerType::class)
->setCustomOption('managerDir', 'image')
->setCustomOption('type', 'image')
->addCssClass('field-text')
->setCustomOption(self::OPTION_MAX_LENGTH, null)
->setCustomOption(self::OPTION_RENDER_AS_HTML, false);

+ 1
- 1
Form/Type/Crud/FileManagerType.php 查看文件

@@ -4,7 +4,7 @@ namespace Lc\SovBundle\Form\Type\Crud;

use Lc\SovBundle\DataTransformer\FileManagerTypeToDataTransformer;
use Lc\SovBundle\Entity\File\File;
use Lc\SovBundle\Doctrine\Extension\FileInterface;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Doctrine\EntityManager;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataTransformerInterface;

+ 13
- 9
Form/Type/User/ChangePasswordFormType.php 查看文件

@@ -13,6 +13,7 @@ namespace Lc\SovBundle\Form\Type\User;

use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
@@ -20,16 +21,19 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Component\Validator\Constraints\NotBlank;

class ChangePasswordFormType extends AbstractType
{

protected $em ;
protected $em;
protected $translatorAdmin;

public function __construct(EntityManager $em)
public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin)
{
$this->em = $em ;
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
}

/**
@@ -49,7 +53,7 @@ class ChangePasswordFormType extends AbstractType
'current_password',
PasswordType::class,
[
'label' => 'Mot de passe actuel',
'label' => 'form.account_password.field.current_password',
'mapped' => false,
'constraints' => [
new NotBlank(),
@@ -59,14 +63,14 @@ class ChangePasswordFormType extends AbstractType
);

$builder->add(
'plainPassword',
'plain_password',
RepeatedType::class,
[
'type' => PasswordType::class,
'mapped' => false,
'first_options' => ['label' => 'Nouveau mot de passe'],
'second_options' => ['label' => 'Nouveau mot de passe (confirmation)'],
'invalid_message' => 'Les deux mots de passe ne correspondent pas.',
'first_options' => ['label' => 'form.account_password.field.new_password'],
'second_options' => ['label' => 'form.account_password.field.new_password_repeat'],
'invalid_message' => $this->translatorAdmin->trans('form.account_password.message.invalid_passwords'),
]
);

@@ -74,7 +78,7 @@ class ChangePasswordFormType extends AbstractType
'submit',
SubmitType::class,
array(
'label' => 'Sauvegarder'
'label' => $this->translatorAdmin->transAction('save')
)
);
}

+ 22
- 27
Form/Type/User/ProfileFormType.php 查看文件

@@ -4,65 +4,60 @@ namespace Lc\SovBundle\Form\Type\User;

use Lc\SovBundle\DataTransformer\FileManagerTypeToDataTransformer;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Entity\File\File;
use Lc\SovBundle\Doctrine\Extension\FileInterface;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\TranslatableMessage;

class ProfileFormType extends AbstractType
{
protected $em ;
protected $em;
protected $translatorAdmin;

public function __construct(EntityManager $em)
public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin)
{
$this->em = $em ;
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$entityName = $this->em->getEntityName(UserInterface::class);

$builder->add(
'firstname',
TextType::class,
array(
'label' => 'Prénom'
)
TextType::class
);

$builder->add(
'lastname',
TextType::class,
array(
'label' => 'Nom'
)
TextType::class
);

$builder->add(
'email',
EmailType::class,
array(
'label' => 'Email'
)
EmailType::class
);

$builder->add(
'phone',
TextType::class,
array(
'label' => 'Téléphone'
)
);
if (property_exists($entityName, 'phone')) {
$builder->add(
'phone',
TextType::class
);
}

$builder->add(
'submit',
SubmitType::class,
array(
'label' => 'Sauvegarder'
)
[
'label' => $this->translatorAdmin->transAction('save')
]
);
}


+ 1
- 0
Resources/assets/app/adminlte/common/app.common.js 查看文件

@@ -26,6 +26,7 @@ global.Tools = Tools;

import { Notification } from './js/notification.js';
global.Notification = Notification;
Notification.init() ;

// Common
import './common.scss';

+ 3
- 0
Resources/assets/app/adminlte/common/common.js 查看文件

@@ -1,4 +1,7 @@

/* Notifications */
//Notification.init() ;

/* Tooltip */
$('[data-toggle="tooltip"]').tooltip();


+ 24
- 13
Resources/assets/app/adminlte/common/js/notification.js 查看文件

@@ -1,34 +1,45 @@

export class Notification {

static setNotifications(notifications) {
static init() {
toastr.options.timeOut = 3000;
toastr.options.positionClass = 'toast-bottom-right';
toastr.options.onHidden = function () {
if ($('#toast-container .toast').length == 1) {
$('#toast-close-all').remove();
}
};
}

static set(notifications) {
var currentNotifications = new Array();
for (var type in notifications) {
for (var key in notifications[type]) {
if (!currentNotifications.includes(notifications[type][key])) {
currentNotifications.push(notifications[type][key]);
self.addNotification(type, notifications[type][key]);
self.add(type, notifications[type][key]);
}
}
}
}

static addNotification(type, text) {

toastr.options.timeOut = 3000;
toastr.options.onHidden = function () {
if ($('#toast-container .toast').length == 0) $('#toast-close-all').remove();
};
static add(type, text) {

toastr[type](text);

if ($('#toast-close-all').length == 0) {
$('#toast-container').prepend('<button id="toast-close-all"><i class="fa fa-times"></i></button>');
let $container = $('#toast-container') ;
let selectorButtonCloseAll = '#toast-close-all' ;
let countMessages = $container.find('.toast').length ;

if ($(selectorButtonCloseAll).length == 0 && countMessages > 2) {
$container.prepend('<button id="toast-close-all"><i class="fa fa-times"></i></button>');
}
$('#toast-close-all').off('click');
$('#toast-close-all').on('click', function () {
$(selectorButtonCloseAll).off('click').on('click', function () {
toastr.remove();
if ($('#toast-container .toast').length == 0) $('#toast-close-all').remove();
if (countMessages == 0) {
$('#toast-close-all').remove();
}
});
}


+ 30
- 12
Resources/assets/app/adminlte/common/scss/_toastr.scss 查看文件

@@ -1,10 +1,29 @@

#toast-container {
width: 350px;
width: 400px;
}

.toast {
float: right
#toast-container .toast {
float: right ;
width: 400px ;
opacity: 1 ;
box-shadow: none !important;
-moz-box-shadow: none !important;
-o-box-shadow: none !important;
-webkit-box-shadow: none !important;

&.success {
background-color: $success !important ;
}
&.danger, &.error {
background-color: $danger !important ;
}
&.info {
background-color: $info !important ;
}
&.warning {
background-color: $warning !important ;
}
}

#toast-container:before:hover {
@@ -15,22 +34,21 @@
#toast-close-all {
border: 0;
position: absolute;
bottom: 7px;
left: -15px;
pointer-events: auto;
z-index: 999999999999999999999;
z-index: 1000;
background: #BD362F;
border-radius: 3px;
color: #fff;
opacity: 0.8;
top: 2px;
width: 50px;
height: 50px;
font-size: 30px;
left: 0px;
font-size: 20px;
text-align: center;
-webkit-text-shadow: 0 1px 0 #fff;
text-shadow: 0 1px 0 #fff;
-moz-box-shadow: 0 0 12px #999;
-webkit-box-shadow: 0 0 12px #999;
box-shadow: 0 0 12px #999;

//@include text-shadow(0 1px 0 #999) ;

border-radius: 50px ;
}


+ 0
- 3
Resources/assets/app/adminlte/field/collection/app.collection.js 查看文件

@@ -9,7 +9,6 @@ $(document).ready(function () {


function initCollectionWidget() {
Tools.log('czefe');

$('.field-collection[data-prototype]').each(function (i, collectionWidget) {
setCollectionWidgetSortable($(collectionWidget));
@@ -65,9 +64,7 @@ function getNumItems($collectionWidget) {
}

function reindexKeyCollectionWidget($collectionWidget) {
Tools.log('ncncnc');
if ($collectionWidget.data('reindex-key')) {
Tools.log('ncncnc');
$collectionWidget.find('.field-collection-item').each(function (i, item) {
$(item).find('input,textarea').each(function (y, field) {
let $field = $(field);

+ 2
- 0
Resources/assets/app/adminlte/field/filemanager/app.filemanager.js 查看文件

@@ -15,6 +15,7 @@ function initFileManager() {
let $field = $(this);
$('#' + $field.data('id')).val("");
$('#' + $field.data('id') + '_preview').prop('src',"");
$('#' + $field.data('id') + '_preview_text').html('Aucun fichier');
});
$('.lc-filemanager-open').off('click');
$('.lc-filemanager-open').on('click', function (e) {
@@ -25,6 +26,7 @@ function initFileManager() {
var path = $(this).attr('data-path')
$('#' + $field.data('id')).val(path);
$('#' + $field.data('id') + '_preview').prop('src',path);
$('#' + $field.data('id') + '_preview_text').html(path);
$('#lc-filemanager-modal').modal('hide');
});
});

+ 2
- 2
Resources/assets/app/adminlte/index/index.js 查看文件

@@ -17,14 +17,14 @@ function lcCrudIndexToggle() {
let toggleRequest = $.ajax({type: "POST", url: toggleUrl, data: {}, dataType: 'json'});

toggleRequest.done(function (response) {
Notification.addNotification('success', 'La propriété a bien été mise à jour.');
Notification.add('success', 'La propriété a bien été mise à jour.');
});

toggleRequest.fail(function () {
toggle.checked = oldValue;
toggle.disabled = true;
toggle.closest('.checkbox-switch').classList.add('disabled');
Notification.addNotification('error', 'Une erreur est survenue.');
Notification.add('error', 'Une erreur est survenue.');
});
});
}

+ 7
- 0
Resources/config/routes.yaml 查看文件

@@ -1,3 +1,10 @@
_liip_imagine:
resource: "@LiipImagineBundle/Resources/config/routing.yaml"

artgris_bundle_file_manager:
resource: "@ArtgrisFileManagerBundle/Controller"
type: annotation
prefix: /manager

sov_login:
path: /login

+ 86
- 0
Resources/translations/admin.fr.yaml 查看文件

@@ -0,0 +1,86 @@

menu:
dashboard: Tableau de bord
page: Pages
user: Utilisateurs
user_index: Liste
account: Mon compte
account_profile: Informations personnelles
account_password: Mot de passe

title:
dashboard: Tableau de bord
index: '%label_plurial%'
sort: Ordonner "%label_plurial%"
new: Ajouter "%label%"
edit: Modifier "%label%" (#%id%)
detail: Voir "%label%" (#%id%)
account:
profile: Mes informations personnelles
change_password: Changer de mot de passe

action:
create: Créer
edit: Éditer
save: Sauvegarder
sort: Ordonner
delete: Supprimer
index_children: Afficher les enfants
index_parent: Retour au parent
back_index: Retour à la liste
save_and_return: Sauvegarder les modifications
save_and_continue: Sauvegarder et continuer l'édition
save_and_add_another: Créer et ajouter un nouvel élément

flash_message:
create: Le contenu "%name%" a été créé avec succès.
update: Le contenu "%name%" a été mis à jour avec succès.
delete: Le contenu "%name%" a été supprimé avec succès.
sort: Position modifiée

entity:
User:
label: Utilisateur
label_plurial: Utilisateurs
fields:
firstname: Prénom
lastname: Nom
Page:
label: Page
label_plurial: Pages
default:
fields:
title: Titre
position: Position
position_help: Position help
description: Description
description_help: Description help
file: Fichier
status: Statut
email: Email
metaTitle: Meta title
metaTitle_help: Affiché dans les résultats de recherche Google
metaDescription: Meta description
metaDescription_help: Affiché dans les résultats de recherche Google
oldUrls: Anciennes urls
devAlias: Alias
gallery: Galerie

panels:
general: Général
configuration: Configuration
gallery: Galerie
seo: Référencement

form:
account_profile:
message:
success: Votre profil a bien été modifié
account_password:
field:
current_password: Mot de passe actuel
new_password: Nouveau mot de passe
new_password_repeat: Nouveau mot de passe (confirmer)
message:
success: Votre mot de passe a bien été modifié
invalid_passwords: Les deux mots de passe ne correspondent pas.

+ 1
- 0
Resources/views/adminlte/block/flash_messages.html.twig 查看文件

@@ -0,0 +1 @@
{# Gérés en Javascript dans layout.html.twig #}

+ 2
- 1
Resources/views/adminlte/block/menu.html.twig 查看文件

@@ -1,5 +1,6 @@
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{% macro render_menu_item(item, is_sub_item = false) %}

{% if item.isMenuSection %}
{% if item.icon is not empty %}
<i class="fa fa-{{ item.icon }}"></i>
@@ -11,7 +12,7 @@
{% if item.icon is not empty %}
<i class="far fa-{{ item.icon }} nav-icon"></i>
{% endif %}
<p>{{ item.label|raw }}</p>
<p>{{ item.label|lc_trans_admin_menu }}</p>
{% if item.hasSubItems %}<i class="right fas fa-angle-left"></i>{% endif %}
</a>
{% endif %}

+ 6
- 4
Resources/views/adminlte/crud/_form.html.twig 查看文件

@@ -13,11 +13,12 @@

{% block configured_stylesheets %}
{{ parent() }}
{% for css_asset in form.vars.ea_crud_form.assets.cssFiles %}

{% for css_asset in form.vars.ea_crud_form.assets.cssAssets %}
<link rel="stylesheet" href="{{ asset(css_asset) }}">
{% endfor %}

{% for webpack_encore_entry in form.vars.ea_crud_form.assets.webpackEncoreEntries %}
{% for webpack_encore_entry in form.vars.ea_crud_form.assets.webpackEncoreAssets %}
{{ ea_call_function_if_exists('encore_entry_link_tags', webpack_encore_entry) }}
{% endfor %}
{% endblock %}
@@ -25,11 +26,12 @@

{% block configured_javascripts %}
{{ parent() }}
{% for js_asset in form.vars.ea_crud_form.assets.jsFiles %}

{% for js_asset in form.vars.ea_crud_form.assets.jsAssets %}
<script src="{{ asset(js_asset) }}"></script>
{% endfor %}

{% for webpack_encore_entry in form.vars.ea_crud_form.assets.webpackEncoreEntries %}
{% for webpack_encore_entry in form.vars.ea_crud_form.assets.webpackEncoreAssets %}
{{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry) }}
{% endfor %}
{% endblock %}

+ 6
- 5
Resources/views/adminlte/crud/action/translatable.html.twig 查看文件

@@ -6,16 +6,17 @@
{% for _locale in app_locales %}
<a class="{{ isIncludedInDropdown|default(false) ? 'dropdown-item' }} {{ action.cssClass }}"
href="{{ action.linkUrl }}&_locale={{ _locale }}"
{% for name, value in action.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
{%- if action.icon %}<i class="action-icon {{ action.icon }}"></i> {% endif -%}
{%- if action.label is not empty -%}{{ action.label }} {{ _locale }}{%- endif -%}
{% for name, value in action.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
{%- if action.icon %}<i class="action-icon {{ action.icon }}"></i> {% endif -%}
{%- if action.label is not empty -%}{{ action.label }} {%- endif -%}
{{ _locale }}
</a>
{% endfor %}
{% elseif 'button' == action.htmlElement %}
<button class="{{ action.cssClass }}" {% for name, value in action.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
<span class="btn-label">
<span class="btn-label">
{%- if action.icon %}<i class="action-icon {{ action.icon }}"></i> {% endif -%}
{%- if action.label is not empty -%}{{ action.label }}{%- endif -%}
{%- if action.label is not empty -%}{{ action.label }}{%- endif -%}
</span>
</button>
{% endif %}

+ 1
- 5
Resources/views/adminlte/crud/edit.html.twig 查看文件

@@ -7,11 +7,7 @@
{% block body_class 'ea-edit ea-edit-' ~ entity.name %}

{% block content_title %}
{%- apply spaceless -%}
{{ ea.crud.customPageTitle is null
? (ea.crud.defaultPageTitle|trans(ea.i18n.translationParameters, 'EasyAdminBundle'))|raw
: ea.crud.customPageTitle|trans(ea.i18n.translationParameters)|raw }}
{%- endapply -%}
{{ 'edit'|lc_trans_admin_title(ea.getEntity().getFqcn(), {id: ea.getEntity().getInstance().getId()}) }}
{% endblock %}

{% block delete_form %}

+ 114
- 11
Resources/views/adminlte/crud/form_theme.html.twig 查看文件

@@ -1,6 +1,89 @@
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{% use '@EasyAdmin/crud/form_theme.html.twig' %}

{% block form_row %}
{% set row_attr = row_attr|merge({
class: row_attr.class|default('') ~ ' form-group'
}) %}

<div {% with { attr: row_attr } %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
<div class="form-widget">
{% set has_prepend_html = ea.field.prepend_html|default(null) is not null %}
{% set has_append_html = ea.field.append_html|default(null) is not null %}
{% set has_input_groups = has_prepend_html or has_append_html %}

{% if has_input_groups %}
<div class="input-group">{% endif %}
{% if has_prepend_html %}
<div class="input-group-prepend">
<span class="input-group-text">{{ ea.field.prepend_html|raw }}</span>
</div>
{% endif %}

{{ form_widget(form) }}

{% if has_append_html %}
<div class="input-group-append">
<span class="input-group-text">{{ ea.field.append_html|raw }}</span>
</div>
{% endif %}
{% if has_input_groups %}</div>{% endif %}

{% set nullable_fields_fqcn = [
'EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField',
'EasyCorp\Bundle\EasyAdminBundle\Field\DateField',
'EasyCorp\Bundle\EasyAdminBundle\Field\TimeField',
] %}
{% if form.vars.ea_crud_form.ea_field.fieldFqcn|default(false) in nullable_fields_fqcn and ea.field.nullable|default(false) %}
<div class="nullable-control">
<label>
<input type="checkbox" {% if data is null %}checked="checked"{% endif %}>
{{ 'label.nullable_field'|trans({}, 'EasyAdminBundle') }}
</label>
</div>
{% endif %}

{% set help_message = name|lc_trans_admin_help(form.parent.vars.data) %}
{% if help_message != '' %}
<small class="form-help">{{ help_message }}</small>
{% endif %}

{{- form_errors(form) -}}
</div>
</div>
{% endblock form_row %}

{% block form_label -%}
{% if label is same as(false) -%}
<label>{# the empty <label> is needed to not break the form design #}</label>
{%- else -%}
{%- if compound is defined and compound -%}
{%- set element = 'legend' -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%}
{%- else -%}
{%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
{%- endif -%}
{% if required -%}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
{% if label is empty -%}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
'%name%': name,
'%id%': id,
}) %}
{%- else -%}
{# {% set label = name|humanize %} #}
{%- endif -%}
{%- endif -%}

{# <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (translation_domain is same as(false)) ? label : label|lower|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</{{ element|default('label') }}> #}
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|lc_trans_admin_field(form.parent.vars.data) }}</{{ element|default('label') }}>

{%- endif -%}
{%- endblock form_label %}

{% block gallery_manager_row %}
{{ block('collection_row') }}
{% endblock gallery_manager_row %}
@@ -9,7 +92,6 @@
{{ block('collection_widget') }}
{% endblock gallery_manager_widget %}


{% block collection_row %}
{% if prototype is defined and not prototype.rendered %}
{% set row_attr = row_attr|merge({ 'data-prototype': form_row(prototype) }) %}
@@ -65,16 +147,32 @@


{% block file_manager_widget %}
{% if form.vars.ea_crud_form.ea_field is not null %}
{% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %}
{% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %}
{% else %}
{% set managerDir = form.parent.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %}
{% set type = form.parent.vars.ea_crud_form.ea_field.customOptions.get('type') %}
{% endif %}

<div class="lc-filemanager row">
<div class="col-md-3 col-xs-12 form-group">
<div class="lc-filemanager row">
{% if type == 'image' %}
<div class="col-md-3 col-xs-12 form-group">
<div class="lc-filemenager-preview card">
<div class="no-image">
<i class="fa fa-image"></i>
</div>
<img src="{{ form.path.vars.value }}" id="{{ form.path.vars.id }}_preview" alt="" class="card-img-top">
</div>
</div>
</div>
{% else %}
<div class="callout callout-success">
<h5><i class="fa fa-file-alt"></i>
<span id="{{ form.path.vars.id }}_preview_text">{{ form.path.vars.value }}</span>
</h5>
</div>
{% endif %}

<div class="col-12">
<div class="input-group">
<div class="input-group-prepend">
@@ -86,7 +184,7 @@
{% endif %}
<button type="button" class="btn btn-primary lc-filemanager-open" data-id="{{ form.path.vars.id }}"
data-toggle="tooltip" title="Sélectionner un fichier"
data-target="{{ path('file_manager', {module:1, conf:'default'})|raw }}">
data-target="{{ path('file_manager', {module:1, conf: managerDir})|raw }}">
<i class="fa fa-folder-open"></i>
</button>
</div>
@@ -103,11 +201,12 @@
{{ form_rest(form) }}
</div>
</div>
</div>
</div>
{% endif %}
{% endblock file_manager_widget %}

{% block checkbox_radio_label -%}
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
{%- if widget is defined -%}
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class or 'switch-custom' in parent_label_class) %}
{% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class or 'switch-custom' in label_attr.class) %}
@@ -145,6 +244,7 @@
{{ name|lc_trad(easyadmin['entity']['name'], 'field') }}
{% else %} #}
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}}

{# {% endif %} #}
{{- form_errors(form) -}}
</label>
@@ -156,16 +256,18 @@
{{ parent() }}

{% if ea_crud_form.form_panels is defined %}

<div class="card card-outline">
<div class="card-header p-0 border-bottom-0">
<ul id="nav-params" class="nav nav-pills" role="navigation">
{% for panel_name, panel_config in ea_crud_form.form_panels|filter(panel_config => not panel_config.form_tab or panel_config.form_tab == tab_name) %}
{% set panel_has_header = panel_config.label|default(false) or panel_config.icon|default(false) %}
<li class="nav-item">
<a href="#panel-{{ panel_name }} " class="nav-link {{ panel_name == 1 ? 'active' }}" data-toggle="tab" role="tab"
<a href="#panel-{{ panel_name }} " class="nav-link {{ panel_name == 1 ? 'active' }}"
data-toggle="tab" role="tab"
aria-controls="panel-{{ panel_name }}">
{{ panel_config.label|raw }}
<i class="fa fa-exclamation-circle invalid-form"></i>
{{ panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn()) }}
<i class="fa fa-exclamation-circle invalid-form"></i>
</a>
</li>
{% endfor %}
@@ -202,7 +304,8 @@
{% if panel_config.icon|default(false) %}
<i class="{{ panel_config.icon }}"></i>
{% endif %}
{{ panel_config.label|raw }}

{{ panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn()) }}

{% if collapsible %}
</a>

+ 5
- 5
Resources/views/adminlte/crud/index.html.twig 查看文件

@@ -2,16 +2,14 @@
{# @var entities \EasyCorp\Bundle\EasyAdminBundle\Collection\EntityDtoCollection #}
{# @var paginator \EasyCorp\Bundle\EasyAdminBundle\Orm\EntityPaginator #}
{% extends ea.templatePath('layout') %}

{% trans_default_domain ea.i18n.translationDomain %}

{% block body_id entities|length > 0 ? 'ea-index-' ~ entities|first.name : '' %}
{% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %}

{% block content_title %}
{%- apply spaceless -%}
{% set default_title = ea.crud.defaultPageTitle('index')|trans(ea.i18n.translationParameters, 'EasyAdminBundle') %}
{{ ea.crud.customPageTitle is null ? default_title|raw : ea.crud.customPageTitle('index')|trans(ea.i18n.translationParameters)|raw }}
{%- endapply -%}
{{ 'index'|lc_trans_admin_title(ea.getEntity().getFqcn()) }}
{% endblock %}

{% block content_breadcrumb %}
@@ -24,6 +22,7 @@
{% endblock page_actions %}

{% block main %}

{# sort can be multiple; let's consider the sorting field the first one #}
{% set sort_field_name = app.request.get('sort')|keys|first %}
{% set sort_order = app.request.get('sort')|first %}
@@ -93,7 +92,7 @@
class="fa fa-fw {{ column_icon }}"></i>
</a>
{% else %}
<span>{{ field.label ? field.label|raw : field.getProperty|raw }}</span>
<span>{{ field.getProperty|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</span>
{% endif %}
</th>
{% endif %}
@@ -207,6 +206,7 @@
{{ parent() }}

<script type="text/javascript">

$(function () {

/* $('.action-delete').on('click', function (e) {

+ 1
- 6
Resources/views/adminlte/crud/new.html.twig 查看文件

@@ -7,14 +7,9 @@
{% block body_class 'ea-new ea-new-' ~ entity.name %}

{% block content_title %}
{%- apply spaceless -%}
{% set default_title = ea.crud.defaultPageTitle('new')|trans(ea.i18n.translationParameters, 'EasyAdminBundle') %}
{{ ea.crud.customPageTitle is null ? default_title|raw : ea.crud.customPageTitle('new')|trans(ea.i18n.translationParameters)|raw }}
{%- endapply -%}
{{ 'new'|lc_trans_admin_title(ea.getEntity().getFqcn()) }}
{% endblock %}



{% block body_javascript %}
{{ parent() }}


+ 9
- 7
Resources/views/adminlte/crud/paginator.html.twig 查看文件

@@ -26,13 +26,15 @@
</li>

{% for page in paginator.pageRange %}
<li class="page-item {{ page == paginator.currentPage ? 'active' }} {{ page is null ? 'disabled' }}">
{% if page is null %}
<span class="page-link">&hellip;</span>
{% else %}
<a class="page-link" href="{{ paginator.generateUrlForPage(page) }}">{{ page }}</a>
{% endif %}
</li>
{% if page != 0 %}
<li class="page-item {{ page == paginator.currentPage ? 'active' }} {{ page is null ? 'disabled' }}">
{% if page is null %}
<span class="page-link">&hellip;</span>
{% else %}
<a class="page-link" href="{{ paginator.generateUrlForPage(page) }}">{{ page }}</a>
{% endif %}
</li>
{% endif %}
{% endfor %}

<li class="page-item {{ not paginator.hasNextPage ? 'disabled' }}">

+ 1
- 2
Resources/views/adminlte/crud/sort.html.twig 查看文件

@@ -8,10 +8,9 @@
{% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %}

{% block content_title %}
Édition position
{{ 'sort'|lc_trans_admin_title(ea.getEntity().getFqcn()) }}
{% endblock %}


{% block content_breadcrumb %}
{{ include('@LcSov/adminlte/block/breadcrumb.html.twig') }}
{% endblock content_breadcrumb %}

+ 4
- 3
Resources/views/adminlte/dashboard.html.twig 查看文件

@@ -1,9 +1,10 @@
{% extends '@LcSov/adminlte/layout.html.twig' %}

{% block content_title 'SovBundle' %}
{% block content_title %}
{{ 'dashboard'|lc_trans_admin_title }}
{% endblock %}

{% block main %}
Bien sur votre tableau de bord
Salut !!!
Tableau de bord par défaut.
{% endblock %}


+ 20
- 3
Resources/views/adminlte/layout.html.twig 查看文件

@@ -27,7 +27,8 @@
<link rel="stylesheet" href="{{ asset(css_asset) }}">
{% endfor %}

{% for webpack_encore_entry in ea.assets.webpackEncoreEntries ?? [] %}

{% for webpack_encore_entry in ea.assets.webpackEncoreAssets ?? [] %}
{{ ea_call_function_if_exists('encore_entry_link_tags', webpack_encore_entry) }}
{% endfor %}
{% endblock %}
@@ -55,6 +56,7 @@

{% block body %}
<body id="{% block body_id %}{% endblock %}" class="sidebar-mini layout-fixed {% block body_class %}{% endblock %}">

{% block javascript_page_layout %}
<script>
document.body.classList.add(
@@ -164,8 +166,8 @@
<script src="{{ asset(js_asset) }}"></script>
{% endfor %}

{% for webpack_encore_entry in ea.assets.webpackEncoreEntries ?? [] %}
{{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry) }}
{% for webpack_encore_entry in ea.assets.webpackEncoreAssets ?? [] %}
{{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry, null, '_default', {'defer': false}) }}
{% endfor %}
{% endblock %}

@@ -179,6 +181,21 @@

{% include '@LcSov/adminlte/filemanager/file-manager-modal.html.twig' %}

{% if app.session is not null and app.session.started %}
{% set flash_messages = app.session.flashbag.all %}
{% if flash_messages|length > 0 %}
<script type="text/javascript">
$(document).ready(function() {
{% for label, messages in flash_messages %}
{% for message in messages %}
Notification.add("{{ label }}", "{{ message|trans|raw|replace({'"': '\"'}) }}");
{% endfor %}
{% endfor %}
});
</script>
{% endif %}
{% endif %}

</body>
{% endblock body %}
</html>

+ 1
- 1
Resources/views/user/change_password.html.twig 查看文件

@@ -2,7 +2,7 @@
{% extends '@LcSov/adminlte/layout.html.twig' %}

{% block content_title %}
Changer de mot de passe
{{ 'account.change_password'|lc_trans_admin_title }}
{% endblock %}

{% block main %}

+ 1
- 1
Resources/views/user/profile.html.twig 查看文件

@@ -1,7 +1,7 @@
{% extends '@LcSov/adminlte/layout.html.twig' %}

{% block content_title %}
Mes informations personnelles
{{ 'account.profile'|lc_trans_admin_title }}
{% endblock %}

{% block main %}

+ 145
- 0
Translation/TranslatorAdmin.php 查看文件

@@ -0,0 +1,145 @@
<?php

namespace Lc\SovBundle\Translation;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use Symfony\Contracts\Translation\TranslatorInterface;

class TranslatorAdmin
{
protected $translator;

const DOMAIN = 'admin';

public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}

public function transAction($action)
{
return $this->trans('action.' . $action);
}

public function transMenu($menu)
{
return $this->trans('menu.' . $menu);
}

public function transFlashMessage($name)
{
return $this->trans('flash_message.' . $name);
}

public function transField($fieldName, $entityClass): string
{
return $this->transEntityThenDefault(
$this->buildTransIdField($fieldName, $entityClass),
$this->buildTransIdField($fieldName, $entityClass, true)
);
}

public function transHelp($fieldName, $entityClass): string
{
$fieldName = $fieldName . '_help';

return $this->transEntityThenDefault(
$this->buildTransIdField($fieldName, $entityClass),
$this->buildTransIdField($fieldName, $entityClass, true),
true
);
}

public function transPanel($panelName, $entityClass): string
{
return $this->transEntityThenDefault(
$this->buildTransIdPanel($panelName, $entityClass),
$this->buildTransIdPanel($panelName, $entityClass, true)
);
}

public function transTitle($pageName, $entityClass = null, $params = [])
{
$entityName = $this->getEntityName($entityClass);

$paramsTranslation = [];

if ($entityName) {
$baseIdEntityLabel = 'entity.' . $entityName;
$paramsTranslation = [
'%label%' => $this->trans($baseIdEntityLabel . '.label'),
'%label_plurial%' => $this->trans($baseIdEntityLabel . '.label_plurial'),
];
}

if (isset($params['id'])) {
$paramsTranslation['%id%'] = $params['id'];
}

return $this->trans(
'title.' . $pageName,
$paramsTranslation
);
}

private function transEntityThenDefault($idTranslationEntity, $idTranslationDefault, $returnEmpty = false): string
{
$translation = $this->trans($idTranslationEntity);

if ($translation == $idTranslationEntity) {
$translation = $this->trans($idTranslationDefault);

if ($translation == $idTranslationDefault) {
if ($returnEmpty) {
$translation = '';
} else {
$translation = $idTranslationEntity;
}
}
}

return $translation;
}

private function buildTransIdField($fieldName, $entityClass, $default = false): string
{
return $this->buildTransIdEntitySection($fieldName, $entityClass, 'fields', $default);
}

private function buildTransIdPanel($panelName, $entityClass, $default = false): string
{
return $this->buildTransIdEntitySection($panelName, $entityClass, 'panels', $default);
}

private function buildTransIdEntitySection($name, $entityClass, $entitySection, $default): string
{
if ($default) {
$entityName = 'default';
} else {
$entityName = $this->getEntityName($entityClass);
}

return 'entity.' . $entityName . '.' . $entitySection . '.' . $name;
}

public function trans($id, $params = [], $domain = self::DOMAIN): string
{
return $this->translator->trans($id, $params, $domain);
}

private function getEntityName($entityClass): string
{
if (is_object($entityClass)) {
$entityClass = get_class($entityClass);
}

if (is_string($entityClass)) {
$entityNameExplode = explode('\\', $entityClass);
return $entityNameExplode[count($entityNameExplode) - 1];
}

return 'default';
}
}

?>

+ 129
- 75
Twig/TwigExtension.php 查看文件

@@ -3,105 +3,159 @@
namespace Lc\SovBundle\Twig;

use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

class TwigExtension extends AbstractExtension
{
protected $em;
protected $kernel;
protected $parameterBag;
protected $cacheManager;
protected $requestStack;
protected $router;

public function __construct(KernelInterface $kernel, ParameterBagInterface $parameterBag, CacheManager $cacheManager, EntityManagerInterface $entityManager, RequestStack $requestStack,UrlGeneratorInterface $router)
{
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
$this->cacheManager = $cacheManager;
$this->em = $entityManager;
$this->requestStack = $requestStack;
$this->router = $router;
protected $em;
protected $kernel;
protected $parameterBag;
protected $cacheManager;
protected $requestStack;
protected $router;
protected $translator;
protected $translatorAdmin;

public function __construct(
KernelInterface $kernel,
ParameterBagInterface $parameterBag,
CacheManager $cacheManager,
EntityManagerInterface $entityManager,
RequestStack $requestStack,
UrlGeneratorInterface $router,
TranslatorInterface $translator,
TranslatorAdmin $translatorAdmin
) {
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
$this->cacheManager = $cacheManager;
$this->em = $entityManager;
$this->requestStack = $requestStack;
$this->router = $router;
$this->translator = $translator;
$this->translatorAdmin = $translatorAdmin;
}

public function getFunctions()
{
return array(
new TwigFunction('lc_liip', [$this, 'lcLiip']),
new TwigFunction('homepage_route', [$this, 'homepageRoute']),
new TwigFunction('page_by_dev_alias', [$this, 'getPageByDevAlias']),
new TwigFunction('translated_urls', [$this, 'getTranslatedUrls'])
);
}


public function getFilters()
{
return [
new TwigFilter('lc_cache', [$this, 'lcCache']),
new TwigFilter('lc_trans_admin_field', [$this, 'lcTransAdminField']),
new TwigFilter('lc_trans_admin_help', [$this, 'lcTransAdminHelp']),
new TwigFilter('lc_trans_admin_panel', [$this, 'lcTransAdminPanel']),
new TwigFilter('lc_trans_admin_menu', [$this, 'lcTransAdminMenu']),
new TwigFilter('lc_trans_admin_title', [$this, 'lcTransAdminTitle']),
new TwigFilter('lc_trans_admin_action', [$this, 'lcTransAdminAction']),
];
}

public function lcCache($file)
{
$cacheTime = filemtime($this->kernel->getProjectDir() . '/public' . $file);
if ($cacheTime) {
return $file . '?c=' . $cacheTime;
} else {
return $file . "?c=0";
}

public function getFunctions()
{
return array(
new TwigFunction('lc_liip', [$this, 'lcLiip']),
new TwigFunction('homepage_route', [$this, 'homepageRoute']),
new TwigFunction('page_by_dev_alias', [$this, 'getPageByDevAlias']),
new TwigFunction('translated_urls', [$this, 'getTranslatedUrls'])
);
}

public function lcTransAdminField($fieldName, $entityClass)
{
return $this->translatorAdmin->transField($fieldName, $entityClass) ;
}

public function lcTransAdminHelp($fieldName, $entityClass)
{
return $this->translatorAdmin->transHelp($fieldName, $entityClass) ;
}

public function lcTransAdminPanel($panelName, $entityClass)
{
return $this->translatorAdmin->transPanel($panelName, $entityClass) ;
}

public function lcTransAdminMenu($menuName)
{
return $this->translatorAdmin->transMenu($menuName);;
}

public function lcTransAdminAction($actionName)
{
return $this->translatorAdmin->transAction($actionName);;
}

public function lcTransAdminTitle($pageName, $entityClass = null, $params = [])
{
return $this->translatorAdmin->transTitle($pageName, $entityClass, $params) ;
}

public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg')
{
if (substr($path, 0, 1) === '/') {
$path = substr($path, 1);
}

if ($path) {
$fileManagerFolder = substr($this->getFileManagerFolder(), 1);

public function getFilters()
{
return [
new TwigFilter('lc_cache', [$this, 'lcCache']),
];
}
if (strpos($path, $fileManagerFolder) === false) {
$path = $fileManagerFolder . '/' . $path;
}

public function lcCache($file)
{
$cacheTime = filemtime($this->kernel->getProjectDir() . '/public' . $file);
if ($cacheTime) {
return $file . '?c=' . $cacheTime;
} else {
return $file . "?c=0";
}
if (file_exists($path)) {
return $this->cacheManager->getBrowserPath($path, $thumb);
}
}

public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg')
{
if (substr($path, 0, 1) === '/') $path = substr($path, 1);

if ($path) {
$fileManagerFolder = substr($this->getFileManagerFolder(), 1) ;
return $this->cacheManager->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb);
}

if (strpos($path, $fileManagerFolder) === false) {
$path = $fileManagerFolder . '/' . $path;
}
function getTranslatedUrls()
{
$ret = array();
$langs = $this->parameterBag->get('app.locales');
$currentRoute = $this->requestStack->getCurrentRequest()->get('_route');

if (file_exists($path)) {
return $this->cacheManager->getBrowserPath($path, $thumb);
}
}
$params = array_merge((array)$this->requestStack->getCurrentRequest()->get('_route_params'), $_GET);

return $this->cacheManager->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb);
if ($currentRoute) {
foreach ($langs as $lg) {
$ret[$lg] = $this->router->generate($currentRoute, array_merge($params, array('_locale' => $lg)));
}
}

function getTranslatedUrls()
{
$ret = array();
$langs = $this->parameterBag->get('app.locales');
$currentRoute = $this->requestStack->getCurrentRequest()->get('_route');
return $ret;
}

$params = array_merge((array)$this->requestStack->getCurrentRequest()->get('_route_params'), $_GET);
public function getFileManagerFolder()
{
return $this->parameterBag->get('app.path_uploads');
}

if ($currentRoute) {
foreach($langs as $lg) {
$ret[$lg] = $this->router->generate($currentRoute, array_merge($params, array('_locale'=>$lg)));
}
}

return $ret;
}

public function getFileManagerFolder()
{
return $this->parameterBag->get('app.path_uploads');
}

public function homepageRoute(){
return $this->parameterBag->get('lc_sov.homepage_route');
}
public function homepageRoute()
{
return $this->parameterBag->get('lc_sov.homepage_route');
}

}

Loading…
取消
儲存