public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore | public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore | ||||
{ | { | ||||
// fields sur la page index | |||||
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { | if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { | ||||
$responseParameters->set('fields', $this->configureFields('index')); | $responseParameters->set('fields', $this->configureFields('index')); | ||||
} | } | ||||
{ | { | ||||
if ($this->isInstanceOf(SortableInterface::class)) { | if ($this->isInstanceOf(SortableInterface::class)) { | ||||
$seoPanel = [ | $seoPanel = [ | ||||
FormField::addPanel('Seo'), | |||||
FormField::addPanel('seo'), | |||||
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp( | TextField::new('metaTitle')->setLabel('Meta Title')->setHelp( | ||||
'Affiché dans les résultats de recherche Google' | 'Affiché dans les résultats de recherche Google' | ||||
)->hideOnIndex(), | )->hideOnIndex(), | ||||
if ($this->isInstanceOf(DevAliasInterface::class)) { | if ($this->isInstanceOf(DevAliasInterface::class)) { | ||||
$confPanel = [ | $confPanel = [ | ||||
FormField::addPanel('Conf'), | |||||
FormField::addPanel('configuration'), | |||||
TextField::new('devAlias')->hideOnIndex(), | TextField::new('devAlias')->hideOnIndex(), | ||||
]; | ]; | ||||
} | } | ||||
->getForm(); | ->getForm(); | ||||
$entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn()); | $entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn()); | ||||
dump($entityManager); | |||||
$repository = $entityManager->getRepository($this->getEntityFqcn()); | $repository = $entityManager->getRepository($this->getEntityFqcn()); | ||||
$sortableForm->handleRequest($context->getRequest()); | $sortableForm->handleRequest($context->getRequest()); |
// the path defined in this method is passed to the Twig asset() function | // the path defined in this method is passed to the Twig asset() function | ||||
->setFaviconPath('favicon.svg') | ->setFaviconPath('favicon.svg') | ||||
// the domain used by default is 'messages' | // the domain used by default is 'messages' | ||||
->setTranslationDomain('lcadmin'); | |||||
->setTranslationDomain('admin'); | |||||
} | } | ||||
public function configureAssets(): Assets | public function configureAssets(): Assets |
return $this->render( | return $this->render( | ||||
'@LcSov/user/change_password.html.twig', | '@LcSov/user/change_password.html.twig', | ||||
[ | [ | ||||
'entity_class' => User::class, | |||||
'form' => $form->createView() | 'form' => $form->createView() | ||||
] | ] | ||||
); | ); |
public function flashMessageAfterPersist(AfterEntityPersistedEvent $event): void | public function flashMessageAfterPersist(AfterEntityPersistedEvent $event): void | ||||
{ | { | ||||
$this->session->getFlashBag()->add('success', new TranslatableMessage('content_admin.flash_message.create', [ | |||||
$this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.create', [ | |||||
'%name%' => (string) $event->getEntityInstance(), | '%name%' => (string) $event->getEntityInstance(), | ||||
], 'admin')); | |||||
])); | |||||
} | } | ||||
public function flashMessageAfterUpdate(AfterEntityUpdatedEvent $event): void | public function flashMessageAfterUpdate(AfterEntityUpdatedEvent $event): void | ||||
{ | { | ||||
$this->session->getFlashBag()->add('success', new TranslatableMessage('content_admin.flash_message.update', [ | |||||
$this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.update', [ | |||||
'%name%' => (string) $event->getEntityInstance(), | '%name%' => (string) $event->getEntityInstance(), | ||||
], 'admin')); | |||||
])); | |||||
} | } | ||||
public function flashMessageAfterDelete(AfterEntityDeletedEvent $event): void | public function flashMessageAfterDelete(AfterEntityDeletedEvent $event): void | ||||
{ | { | ||||
$this->session->getFlashBag()->add('success', new TranslatableMessage('content_admin.flash_message.delete', [ | |||||
$this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.delete', [ | |||||
'%name%' => (string) $event->getEntityInstance(), | '%name%' => (string) $event->getEntityInstance(), | ||||
], 'admin')); | |||||
])); | |||||
} | } | ||||
} | } |
function initCollectionWidget() { | function initCollectionWidget() { | ||||
Tools.log('czefe'); | |||||
$('.field-collection[data-prototype]').each(function (i, collectionWidget) { | $('.field-collection[data-prototype]').each(function (i, collectionWidget) { | ||||
setCollectionWidgetSortable($(collectionWidget)); | setCollectionWidgetSortable($(collectionWidget)); | ||||
} | } | ||||
function reindexKeyCollectionWidget($collectionWidget) { | function reindexKeyCollectionWidget($collectionWidget) { | ||||
Tools.log('ncncnc'); | |||||
if ($collectionWidget.data('reindex-key')) { | if ($collectionWidget.data('reindex-key')) { | ||||
Tools.log('ncncnc'); | |||||
$collectionWidget.find('.field-collection-item').each(function (i, item) { | $collectionWidget.find('.field-collection-item').each(function (i, item) { | ||||
$(item).find('input,textarea').each(function (y, field) { | $(item).find('input,textarea').each(function (y, field) { | ||||
let $field = $(field); | let $field = $(field); |
content_admin: | |||||
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. | |||||
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. | |||||
form: | |||||
title: | |||||
edit: Modifier "%name%" | |||||
new: Ajouter "%name%" | |||||
menu: | |||||
dashboard: Tableau de bord | |||||
account: | |||||
label: Mon compte | |||||
childs: | |||||
profile: Informations personnelles | |||||
password: Mot de passe | |||||
entity: | |||||
default: | |||||
fields: | |||||
title: Titre | |||||
position: Position | |||||
position_help: Position help | |||||
description: Description | |||||
description_help: Description help | |||||
file: Fichier | |||||
status: Statut | |||||
panels: | |||||
general: Général | |||||
configuration: Configuration | |||||
gallery: Galerie | |||||
seo: Référencement |
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} | {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} | ||||
{% macro render_menu_item(item, is_sub_item = false) %} | {% macro render_menu_item(item, is_sub_item = false) %} | ||||
{% if item.isMenuSection %} | {% if item.isMenuSection %} | ||||
{% if item.icon is not empty %} | {% if item.icon is not empty %} | ||||
<i class="fa fa-{{ item.icon }}"></i> | <i class="fa fa-{{ item.icon }}"></i> | ||||
{% if item.icon is not empty %} | {% if item.icon is not empty %} | ||||
<i class="far fa-{{ item.icon }} nav-icon"></i> | <i class="far fa-{{ item.icon }} nav-icon"></i> | ||||
{% endif %} | {% 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 %} | {% if item.hasSubItems %}<i class="right fas fa-angle-left"></i>{% endif %} | ||||
</a> | </a> | ||||
{% endif %} | {% endif %} |
{% block body_class 'ea-edit ea-edit-' ~ entity.name %} | {% block body_class 'ea-edit ea-edit-' ~ entity.name %} | ||||
{% block content_title %} | {% 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()) }} | |||||
{% endblock %} | {% endblock %} | ||||
{% block delete_form %} | {% block delete_form %} |
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} | {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} | ||||
{% use '@EasyAdmin/crud/form_theme.html.twig' %} | {% 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_field(ea.getEntity().getFqcn(), true) %} | |||||
{% 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') }}> | |||||
{%- endif -%} | |||||
{%- endblock form_label %} | |||||
{% block gallery_manager_row %} | {% block gallery_manager_row %} | ||||
{{ block('collection_row') }} | {{ block('collection_row') }} | ||||
{% endblock gallery_manager_row %} | {% endblock gallery_manager_row %} | ||||
{{ block('collection_widget') }} | {{ block('collection_widget') }} | ||||
{% endblock gallery_manager_widget %} | {% endblock gallery_manager_widget %} | ||||
{% block collection_row %} | {% block collection_row %} | ||||
{% if prototype is defined and not prototype.rendered %} | {% if prototype is defined and not prototype.rendered %} | ||||
{% set row_attr = row_attr|merge({ 'data-prototype': form_row(prototype) }) %} | {% set row_attr = row_attr|merge({ 'data-prototype': form_row(prototype) }) %} | ||||
{{ name|lc_trad(easyadmin['entity']['name'], 'field') }} | {{ name|lc_trad(easyadmin['entity']['name'], 'field') }} | ||||
{% else %} #} | {% else %} #} | ||||
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}} | {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}} | ||||
{# {% endif %} #} | {# {% endif %} #} | ||||
{{- form_errors(form) -}} | {{- form_errors(form) -}} | ||||
</label> | </label> | ||||
{{ parent() }} | {{ parent() }} | ||||
{% if ea_crud_form.form_panels is defined %} | {% if ea_crud_form.form_panels is defined %} | ||||
<div class="card card-outline"> | <div class="card card-outline"> | ||||
<div class="card-header p-0 border-bottom-0"> | <div class="card-header p-0 border-bottom-0"> | ||||
<ul id="nav-params" class="nav nav-pills" role="navigation"> | <ul id="nav-params" class="nav nav-pills" role="navigation"> | ||||
<li class="nav-item"> | <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 }}"> | aria-controls="panel-{{ panel_name }}"> | ||||
{{ panel_config.label|raw }} | |||||
{{ panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn()) }} | |||||
<i class="fa fa-exclamation-circle invalid-form"></i> | <i class="fa fa-exclamation-circle invalid-form"></i> | ||||
</a> | </a> | ||||
</li> | </li> |
{% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %} | {% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %} | ||||
{% block content_title %} | {% 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 %} | {% endblock %} | ||||
{% block content_breadcrumb %} | {% block content_breadcrumb %} | ||||
{% endblock page_actions %} | {% endblock page_actions %} | ||||
{% block main %} | {% block main %} | ||||
{# sort can be multiple; let's consider the sorting field the first one #} | {# 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_field_name = app.request.get('sort')|keys|first %} | ||||
{% set sort_order = app.request.get('sort')|first %} | {% set sort_order = app.request.get('sort')|first %} | ||||
class="fa fa-fw {{ column_icon }}"></i> | class="fa fa-fw {{ column_icon }}"></i> | ||||
</a> | </a> | ||||
{% else %} | {% else %} | ||||
<span>{{ field.label ? field.label|raw : field.getProperty|raw }}</span> | |||||
<span>{{ field.getProperty|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</span> | |||||
{% endif %} | {% endif %} | ||||
</th> | </th> | ||||
{% endif %} | {% endif %} | ||||
{{ parent() }} | {{ parent() }} | ||||
<script type="text/javascript"> | <script type="text/javascript"> | ||||
$(function () { | $(function () { | ||||
/* $('.action-delete').on('click', function (e) { | /* $('.action-delete').on('click', function (e) { |
{% block body_class 'ea-new ea-new-' ~ entity.name %} | {% block body_class 'ea-new ea-new-' ~ entity.name %} | ||||
{% block content_title %} | {% 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 %} | {% endblock %} | ||||
{% endfor %} | {% endfor %} | ||||
{% for webpack_encore_entry in ea.assets.webpackEncoreEntries ?? [] %} | {% for webpack_encore_entry in ea.assets.webpackEncoreEntries ?? [] %} | ||||
{{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry) }} | |||||
{{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry, null, '_default', {'defer': false}) }} | |||||
{% endfor %} | {% endfor %} | ||||
{% endblock %} | {% endblock %} | ||||
{% if app.session is not null and app.session.started %} | {% if app.session is not null and app.session.started %} | ||||
{% set flash_messages = app.session.flashbag.all %} | {% set flash_messages = app.session.flashbag.all %} | ||||
{% if flash_messages|length > 0 %} | {% if flash_messages|length > 0 %} | ||||
{% for label, messages in flash_messages %} | |||||
{% for message in messages %} | |||||
<script type="text/javascript"> | |||||
Notification.add("{{ label }}", "{{ message|trans|raw|replace({'"': '\"'}) }}") ; | |||||
</script> | |||||
<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 %} | {% endfor %} | ||||
{% endfor %} | |||||
}); | |||||
</script> | |||||
{% endif %} | {% endif %} | ||||
{% endif %} | {% endif %} | ||||
namespace Lc\SovBundle\Twig; | namespace Lc\SovBundle\Twig; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | |||||
use Liip\ImagineBundle\Imagine\Cache\CacheManager; | use Liip\ImagineBundle\Imagine\Cache\CacheManager; | ||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||||
use Symfony\Component\HttpFoundation\RequestStack; | use Symfony\Component\HttpFoundation\RequestStack; | ||||
use Symfony\Component\HttpKernel\KernelInterface; | use Symfony\Component\HttpKernel\KernelInterface; | ||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||||
use Symfony\Contracts\Translation\TranslatorInterface; | |||||
use Twig\Extension\AbstractExtension; | use Twig\Extension\AbstractExtension; | ||||
use Twig\TwigFilter; | use Twig\TwigFilter; | ||||
use Twig\TwigFunction; | use Twig\TwigFunction; | ||||
class TwigExtension extends AbstractExtension | 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; | |||||
public function __construct( | |||||
KernelInterface $kernel, | |||||
ParameterBagInterface $parameterBag, | |||||
CacheManager $cacheManager, | |||||
EntityManagerInterface $entityManager, | |||||
RequestStack $requestStack, | |||||
UrlGeneratorInterface $router, | |||||
TranslatorInterface $translator | |||||
) { | |||||
$this->kernel = $kernel; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->cacheManager = $cacheManager; | |||||
$this->em = $entityManager; | |||||
$this->requestStack = $requestStack; | |||||
$this->router = $router; | |||||
$this->translator = $translator; | |||||
} | |||||
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_panel', [$this, 'lcTransAdminPanel']), | |||||
new TwigFilter('lc_trans_admin_menu', [$this, 'lcTransAdminMenu']), | |||||
new TwigFilter('lc_trans_admin_title', [$this, 'lcTransAdminTitle']), | |||||
]; | |||||
} | |||||
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, $isHelp = false) | |||||
{ | |||||
if ($isHelp) { | |||||
$fieldName = $fieldName . '_help'; | |||||
} | } | ||||
$entityName = $this->getEntityName($entityClass) ; | |||||
public function getFilters() | |||||
{ | |||||
return [ | |||||
new TwigFilter('lc_cache', [$this, 'lcCache']), | |||||
]; | |||||
} | |||||
$entityLabel = 'entity.' . $entityName . '.fields.' . $fieldName; | |||||
$translatedLabel = $this->translator->trans($entityLabel, [], 'admin'); | |||||
if ($translatedLabel == $entityLabel) { | |||||
$defaultLabel = 'entity.default.fields.' . $fieldName; | |||||
$translatedLabel = $this->translator->trans($defaultLabel, [], 'admin'); | |||||
public function lcCache($file) | |||||
{ | |||||
$cacheTime = filemtime($this->kernel->getProjectDir() . '/public' . $file); | |||||
if ($cacheTime) { | |||||
return $file . '?c=' . $cacheTime; | |||||
if ($translatedLabel == $defaultLabel) { | |||||
if ($isHelp) { | |||||
$translatedLabel = ''; | |||||
} else { | } else { | ||||
return $file . "?c=0"; | |||||
$translatedLabel = $entityLabel; | |||||
} | } | ||||
} | |||||
} | } | ||||
public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') | |||||
{ | |||||
if (substr($path, 0, 1) === '/') $path = substr($path, 1); | |||||
return $translatedLabel; | |||||
} | |||||
if ($path) { | |||||
$fileManagerFolder = substr($this->getFileManagerFolder(), 1) ; | |||||
public function lcTransAdminPanel($panelName, $entityClass) | |||||
{ | |||||
$entityName = $this->getEntityName($entityClass) ; | |||||
if (strpos($path, $fileManagerFolder) === false) { | |||||
$path = $fileManagerFolder . '/' . $path; | |||||
} | |||||
$panelLabel = 'entity.' . $entityName . '.panels.' . $panelName; | |||||
$translatedLabel = $this->translator->trans($panelLabel, [], 'admin'); | |||||
if (file_exists($path)) { | |||||
return $this->cacheManager->getBrowserPath($path, $thumb); | |||||
} | |||||
} | |||||
if ($translatedLabel == $panelLabel) { | |||||
$defaultLabel = 'entity.default.panels.' . $panelName; | |||||
$translatedLabel = $this->translator->trans($defaultLabel, [], 'admin'); | |||||
return $this->cacheManager->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb); | |||||
if ($translatedLabel == $defaultLabel) { | |||||
$translatedLabel = $panelLabel; | |||||
} | |||||
} | } | ||||
function getTranslatedUrls() | |||||
{ | |||||
$ret = array(); | |||||
$langs = $this->parameterBag->get('app.locales'); | |||||
$currentRoute = $this->requestStack->getCurrentRequest()->get('_route'); | |||||
return $translatedLabel; | |||||
} | |||||
$params = array_merge((array)$this->requestStack->getCurrentRequest()->get('_route_params'), $_GET); | |||||
public function lcTransAdminMenu($menuName) | |||||
{ | |||||
$menuLabel = 'menu.'.$menuName; | |||||
$translatedLabel = $this->translator->trans($menuLabel, [], 'admin'); | |||||
if ($currentRoute) { | |||||
foreach($langs as $lg) { | |||||
$ret[$lg] = $this->router->generate($currentRoute, array_merge($params, array('_locale'=>$lg))); | |||||
} | |||||
} | |||||
return $translatedLabel ; | |||||
} | |||||
public function lcTransAdminTitle($pageName, $entityClass) | |||||
{ | |||||
$entityName = $this->getEntityName($entityClass) ; | |||||
$translatedLabel = '' ; | |||||
return $ret; | |||||
if(Crud::PAGE_INDEX == $pageName) { | |||||
$titleLabel = 'entity.'.$entityName.'.label_plurial' ; | |||||
$translatedLabel = $this->translator->trans($titleLabel, [], 'admin'); | |||||
} | } | ||||
elseif(Crud::PAGE_EDIT == $pageName) { | |||||
$entityLabel = 'entity.'.$entityName.'.label' ; | |||||
$translatedEntityLabel = $this->translator->trans($entityLabel, [],'admin'); | |||||
$translatedLabel = $this->translator->trans('form.title.edit', ['%name%' => $translatedEntityLabel], 'admin'); | |||||
} | |||||
elseif(Crud::PAGE_NEW == $pageName) { | |||||
$entityLabel = 'entity.'.$entityName.'.label' ; | |||||
$translatedEntityLabel = $this->translator->trans($entityLabel, [], 'admin'); | |||||
$translatedLabel = $this->translator->trans('form.title.new', ['%name%' => $translatedEntityLabel], 'admin'); | |||||
} | |||||
return $translatedLabel ; | |||||
} | |||||
public function getFileManagerFolder() | |||||
{ | |||||
return $this->parameterBag->get('app.path_uploads'); | |||||
public function getEntityName($entityClass) | |||||
{ | |||||
$entityNameExplode = explode('\\', $entityClass); | |||||
$entityName = strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||||
return $entityName ; | |||||
} | |||||
public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') | |||||
{ | |||||
if (substr($path, 0, 1) === '/') { | |||||
$path = substr($path, 1); | |||||
} | } | ||||
public function homepageRoute(){ | |||||
return $this->parameterBag->get('lc_sov.homepage_route'); | |||||
if ($path) { | |||||
$fileManagerFolder = substr($this->getFileManagerFolder(), 1); | |||||
if (strpos($path, $fileManagerFolder) === false) { | |||||
$path = $fileManagerFolder . '/' . $path; | |||||
} | |||||
if (file_exists($path)) { | |||||
return $this->cacheManager->getBrowserPath($path, $thumb); | |||||
} | |||||
} | } | ||||
return $this->cacheManager->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb); | |||||
} | |||||
function getTranslatedUrls() | |||||
{ | |||||
$ret = array(); | |||||
$langs = $this->parameterBag->get('app.locales'); | |||||
$currentRoute = $this->requestStack->getCurrentRequest()->get('_route'); | |||||
$params = array_merge((array)$this->requestStack->getCurrentRequest()->get('_route_params'), $_GET); | |||||
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'); | |||||
} | |||||
} | } |