backports murph-skeleton
This commit is contained in:
parent
719e97f20b
commit
f239861f22
|
@ -8,6 +8,7 @@ use App\Core\Factory\Site\MenuFactory;
|
|||
use App\Core\Form\Site\MenuType;
|
||||
use App\Core\Repository\Site\NavigationRepositoryQuery;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
|
@ -18,9 +19,21 @@ class TreeAdminController extends AdminController
|
|||
/**
|
||||
* @Route("/", name="admin_site_tree_index")
|
||||
*/
|
||||
public function index(NavigationRepositoryQuery $navigationQuery): Response
|
||||
public function index(NavigationRepositoryQuery $navigationQuery, Session $session): Response
|
||||
{
|
||||
$navigation = $navigationQuery->create()->findOne();
|
||||
$navigation = null;
|
||||
|
||||
if ($session->has('site_tree_last_navigation')) {
|
||||
$navigation = $navigationQuery->create()
|
||||
->where('.id = :id')
|
||||
->setParameter(':id', (int) $session->get('site_tree_last_navigation'))
|
||||
->findOne()
|
||||
;
|
||||
}
|
||||
|
||||
if (null === $navigation) {
|
||||
$navigation = $navigationQuery->create()->findOne();
|
||||
}
|
||||
|
||||
if (null === $navigation) {
|
||||
$this->addFlash('warning', 'You must add a navigation.');
|
||||
|
@ -39,10 +52,13 @@ class TreeAdminController extends AdminController
|
|||
public function navigation(
|
||||
Navigation $navigation,
|
||||
NavigationRepositoryQuery $navigationQuery,
|
||||
MenuFactory $menuFactory
|
||||
MenuFactory $menuFactory,
|
||||
Session $session
|
||||
): Response {
|
||||
$navigations = $navigationQuery->create()->find();
|
||||
|
||||
$session->set('site_tree_last_navigation', $navigation->getId());
|
||||
|
||||
$forms = [
|
||||
'menu' => $this->createForm(MenuType::class, $menuFactory->create())->createView(),
|
||||
'menus' => [],
|
||||
|
|
|
@ -44,6 +44,11 @@ class Navigation implements EntityInterface
|
|||
*/
|
||||
private $menus;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=10)
|
||||
*/
|
||||
private $locale = 'en';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->menus = new ArrayCollection();
|
||||
|
@ -135,4 +140,16 @@ class Navigation implements EntityInterface
|
|||
{
|
||||
return $this->getCode() ? $this->getCode() : 'navigation_'.$this->getId();
|
||||
}
|
||||
|
||||
public function getLocale(): ?string
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
public function setLocale(string $locale): self
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,17 @@ class UserFactory
|
|||
$this->encoder = $encoder;
|
||||
}
|
||||
|
||||
public function create(): User
|
||||
public function create(?string $email = null, ?string $password = null): User
|
||||
{
|
||||
$entity = new User();
|
||||
|
||||
if (!empty($email)) {
|
||||
$entity->setEmail($email);
|
||||
}
|
||||
|
||||
$entity->setPassword($this->encoder->encodePassword(
|
||||
$entity,
|
||||
$this->tokenGenerator->generateToken()
|
||||
!empty($password) ? $password : $this->tokenGenerator->generateToken()
|
||||
));
|
||||
|
||||
return $entity;
|
||||
|
|
|
@ -8,6 +8,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
|
||||
class NavigationType extends AbstractType
|
||||
{
|
||||
|
@ -54,6 +55,21 @@ class NavigationType extends AbstractType
|
|||
],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add(
|
||||
'locale',
|
||||
TextType::class,
|
||||
[
|
||||
'label' => 'Locale',
|
||||
'required' => true,
|
||||
'attr' => [
|
||||
],
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new Length(['min' => 2, 'max' => 10]),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
|
|
@ -94,4 +94,29 @@ abstract class RepositoryQuery
|
|||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function filterHandler(string $name, $value)
|
||||
{
|
||||
}
|
||||
|
||||
public function useFilters(array $filters)
|
||||
{
|
||||
foreach ($filters as $name => $value) {
|
||||
if (null === $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_int($value) || is_bool($value)) {
|
||||
$this->andWhere('.'.$name.' = :'.$name);
|
||||
$this->setParameter(':'.$name, $value);
|
||||
} elseif (is_string($value)) {
|
||||
$this->andWhere('.'.$name.' LIKE :'.$name);
|
||||
$this->setParameter(':'.$name, '%'.$value.'%');
|
||||
} else {
|
||||
$this->filterHandler($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"This is a test of translation": "Ceci est un test de traduction"
|
||||
"The code is not valid.": "Le code n'est pas valide."
|
||||
"Double authentication enabled.": "Double authentification activée."
|
||||
"Double authentication disabled.": "Double authentification désactivée."
|
||||
|
@ -127,3 +128,4 @@
|
|||
"Anyway": "Peu importe"
|
||||
"Yes": "Oui"
|
||||
"No": "Non"
|
||||
"Locale": "Langue"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="row">
|
||||
<div class="col-12 p-3">
|
||||
<div class="row">
|
||||
{% for item in ['label', 'code', 'domain'] %}
|
||||
{% for item in ['label', 'domain', 'locale', 'code'] %}
|
||||
<div class="col-12">
|
||||
{{ form_row(form[item]) }}
|
||||
</div>
|
||||
|
|
|
@ -34,16 +34,21 @@
|
|||
|
||||
{{ entity.label }}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<span class="font-weight-bold pb-2 d-block">{{ 'Code'|trans }}</span>
|
||||
|
||||
{{ entity.code }}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<span class="font-weight-bold pb-2 d-block">{{ 'Domain'|trans }}</span>
|
||||
|
||||
{{ entity.domain }}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<span class="font-weight-bold pb-2 d-block">{{ 'Locale'|trans }}</span>
|
||||
|
||||
{{ entity.locale }}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<span class="font-weight-bold pb-2 d-block">{{ 'Code'|trans }}</span>
|
||||
|
||||
{{ entity.code }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -32,6 +32,16 @@ class SiteRouteLoader extends Loader
|
|||
$routes = new RouteCollection();
|
||||
$navigations = $this->navigationQuery->find();
|
||||
|
||||
$uniqueness = [];
|
||||
|
||||
foreach ($navigations as $navigation) {
|
||||
if (!isset($uniqueness[$navigation->getDomain()])) {
|
||||
$uniqueness[$navigation->getDomain()] = true;
|
||||
} else {
|
||||
$uniqueness[$navigation->getDomain()] = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($navigations as $navigation) {
|
||||
foreach ($navigation->getMenus() as $menu) {
|
||||
foreach ($menu->getRootNode()->getAllChildren() as $node) {
|
||||
|
@ -51,6 +61,7 @@ class SiteRouteLoader extends Loader
|
|||
|
||||
$defaults = [
|
||||
'_controller' => $node->getController() ?? PageController::class.'::show',
|
||||
'_locale' => $navigation->getLocale(),
|
||||
'_node' => $node->getId(),
|
||||
'_menu' => $menu->getId(),
|
||||
'_page' => $node->getPage() ? $node->getPage()->getId() : null,
|
||||
|
@ -69,7 +80,15 @@ class SiteRouteLoader extends Loader
|
|||
}
|
||||
}
|
||||
|
||||
$route = new Route($node->getUrl(), $defaults, $requirements);
|
||||
$requirements['_locale'] = $navigation->getLocale();
|
||||
|
||||
$url = $node->getUrl();
|
||||
|
||||
if (!$uniqueness[$navigation->getDomain()]) {
|
||||
$url = sprintf('/%s%s', $navigation->getLocale(), $url);
|
||||
}
|
||||
|
||||
$route = new Route($url, $defaults, $requirements);
|
||||
$route->setHost($navigation->getDomain());
|
||||
|
||||
$routes->add($node->getRouteName(), $route);
|
||||
|
|
Loading…
Reference in New Issue