Skip to content

Commit

Permalink
further integration of EAB with Nucleos [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed Apr 2, 2023
1 parent 674e665 commit 68245a4
Show file tree
Hide file tree
Showing 53 changed files with 544 additions and 1,633 deletions.
Expand Up @@ -17,7 +17,7 @@

class FormTypeChoiceEvent
{
public function __construct(private readonly FormTypesChoices $choices)
public function __construct(private FormTypesChoices $choices)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/system/CategoriesBundle/Entity/Category.php
Expand Up @@ -32,7 +32,7 @@ class Category
#[ORM\Id]
#[ORM\Column]
#[ORM\GeneratedValue]
private ?int $id;
private ?int $id = null;

#[ORM\Column]
#[Gedmo\TreeLeft]
Expand Down Expand Up @@ -245,9 +245,9 @@ public function setDisplayDesc(array $displayDesc): self
return $this;
}

public function getStatus(): bool
public function getStatus(): string
{
return 'A' === $this->status;
return $this->status;
}

public function setStatus($status): self
Expand Down
8 changes: 8 additions & 0 deletions src/system/CategoriesBundle/Menu/ExtensionMenu.php
Expand Up @@ -14,12 +14,20 @@
namespace Zikula\CategoriesBundle\Menu;

use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use Zikula\CategoriesBundle\Entity\Category;
use Zikula\ThemeBundle\ExtensionMenu\AbstractExtensionMenu;
use function Symfony\Component\Translation\t;

class ExtensionMenu extends AbstractExtensionMenu
{
protected function getAdmin(): iterable
{
yield MenuItem::linkToCrud(t('Categories'), 'fas fa-sitemap', Category::class);
yield MenuItem::linkToCrud(t('Add category'), 'fas fa-plus', Category::class)
->setAction('new');

yield MenuItem::section('Old stuff');

yield MenuItem::linktoRoute('Category tree', 'fas fa-tree', 'zikulacategoriesbundle_category_listcategories')
->setPermission('ROLE_EDITOR');
yield MenuItem::linktoRoute('Category registry', 'fas fa-archive', 'zikulacategoriesbundle_registry_edit')
Expand Down
13 changes: 10 additions & 3 deletions src/system/LegalBundle/Controller/UserController.php
Expand Up @@ -14,17 +14,18 @@
namespace Zikula\LegalBundle\Controller;

use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Zikula\Bundle\CoreBundle\Site\SiteDefinitionInterface;
use Zikula\LegalBundle\Form\Type\AcceptPoliciesType;
use Zikula\LegalBundle\Helper\AcceptPoliciesHelper;
use Zikula\LegalBundle\LegalConstant;
use Zikula\ThemeBundle\Controller\Dashboard\UserDashboardController;
use Zikula\UsersBundle\Api\ApiInterface\CurrentUserApiInterface;
use Zikula\UsersBundle\Entity\User;
use Zikula\UsersBundle\Helper\AccessHelper;
Expand All @@ -44,9 +45,15 @@ public function __construct(
* Redirects to the Terms of Use legal document.
*/
#[Route('', name: 'zikulalegalbundle_user_index', methods: ['GET'])]
public function index(RouterInterface $router): RedirectResponse
public function index(AdminUrlGenerator $urlGenerator): RedirectResponse
{
return $this->redirectToRoute('zikulalegalbundle_user_legalnotice');
return $this->redirect(
$urlGenerator
->setDashboard(UserDashboardController::class)
->setController(self::class)
->setRoute('zikulalegalbundle_user_legalnotice')
->generateUrl()
);
}

/**
Expand Down
@@ -1,28 +1,30 @@
{{ pageSetVar('title', 'Site policies'|trans) }}
<h2>{{ 'Site policies'|trans }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{% if login %}
<div class="alert alert-danger">
{% trans %}In order to log in you must accept this site\'s policies. If you have accepted the site\'s policies in the past, then they have been updated and we ask that you review the changes.{% endtrans %}
<hr />
{% trans %}If you leave this page without successfully accepting the policies, then you will not be logged in.{% endtrans %}
</div>
{% endif %}
{% block content_title 'Site policies'|trans %}
{% block main %}
{% if login %}
<div class="alert alert-danger">
{% trans %}In order to log in you must accept this site\'s policies. If you have accepted the site\'s policies in the past, then they have been updated and we ask that you review the changes.{% endtrans %}
<hr />
{% trans %}If you leave this page without successfully accepting the policies, then you will not be logged in.{% endtrans %}
</div>
{% endif %}

<form id="legal_user_acceptpolicies" action="{{ path('zikulalegalbundle_user_acceptpolicies') }}" method="post">
<div>
{{ form_start(form) }}
{{ form_errors(form) }}
<fieldset>
{{ form_row(form.acceptedpolicies_policies) }}
{{ include('@ZikulaLegal/Include/acceptPolicies.html.twig') }}
</fieldset>
<div class="form-group row">
<div class="col-md-9 offset-md-3">
{{ form_widget(form.submit) }}
<a class="btn btn-danger" href="{{ path('home') }}" title="{% trans %}Cancel{% endtrans %}">{% trans %}Cancel and logout{% endtrans %}</a>
</div>
</div>
{{ form_end(form) }}
</div>
</form>
<form id="legal_user_acceptpolicies" action="{{ path('zikulalegalbundle_user_acceptpolicies') }}" method="post">
<div>
{{ form_start(form) }}
{{ form_errors(form) }}
<fieldset>
{{ form_row(form.acceptedpolicies_policies) }}
{{ include('@ZikulaLegal/Include/acceptPolicies.html.twig') }}
</fieldset>
<div class="form-group row">
<div class="col-md-9 offset-md-3">
{{ form_widget(form.submit) }}
<a class="btn btn-danger" href="{{ path('home') }}" title="{% trans %}Cancel{% endtrans %}">{% trans %}Cancel and logout{% endtrans %}</a>
</div>
</div>
{{ form_end(form) }}
</div>
</form>
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Accessibility statement for %s%'|trans({ '%s%': siteName() })) }}
<h2>{{ 'Accessibility statement for %s%'|trans({ '%s%': siteName() }) }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/accessibilityStatement.html.twig') }}
{% block content_title 'Accessibility statement for %s%'|trans({ '%s%': siteName() }) %}
{% block main %}
{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/accessibilityStatement.html.twig') }}
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Cancellation right policy for %s%'|trans({ '%s%': siteName() })) }}
<h2>{{ 'Cancellation right policy for %s%'|trans({ '%s%': siteName() }) }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/cancellationRightPolicy.html.twig') }}
{% block content_title 'Cancellation right policy for %s%'|trans({ '%s%': siteName() }) %}
{% block main %}
{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/cancellationRightPolicy.html.twig') }}
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Legal notice for %s%'|trans({ '%s%': siteName() })) }}
<h2>{{ 'Legal notice for %s%'|trans({ '%s%': siteName() }) }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/legalNotice.html.twig') }}
{% block content_title 'Legal notice for %s%'|trans({ '%s%': siteName() }) %}
{% block main %}
{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/legalNotice.html.twig') }}
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Policy not available'|trans) }}
<h2>{{ 'Policy not available'|trans }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

<p>{% trans %}The selected policy is not available.{% endtrans %}</p>
{% block content_title 'Policy not available'|trans %}
{% block main %}
<p>{% trans %}The selected policy is not available.{% endtrans %}</p>
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Privacy policy for %s%'|trans({ '%s%': siteName() })) }}
<h2>{{ 'Privacy policy for %s%'|trans({ '%s%': siteName() }) }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/privacyPolicy.html.twig') }}
{% block content_title 'Privacy policy for %s%'|trans({ '%s%': siteName() }) %}
{% block main %}
{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/privacyPolicy.html.twig') }}
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Terms of use for %s%'|trans({ '%s%': siteName() })) }}
<h2>{{ 'Terms of use for %s%'|trans({ '%s%': siteName() }) }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/termsOfUse.html.twig') }}
{% block content_title 'Terms of use for %s%'|trans({ '%s%': siteName() }) %}
{% block main %}
{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/termsOfUse.html.twig') }}
{% endblock %}
@@ -1,4 +1,6 @@
{{ pageSetVar('title', 'Trade conditions for %s%'|trans({ '%s%': siteName() })) }}
<h2>{{ 'Trade conditions for %s%'|trans({ '%s%': siteName() }) }}</h2>
{% extends '@EasyAdmin/page/content.html.twig' %}

{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/tradeConditions.html.twig') }}
{% block content_title 'Trade conditions for %s%'|trans({ '%s%': siteName() }) %}
{% block main %}
{{ include('@ZikulaLegal/' ~ app.request.locale ~ '/tradeConditions.html.twig') }}
{% endblock %}
3 changes: 1 addition & 2 deletions src/system/ProfileBundle/Bridge/ProfileBundleBridge.php
Expand Up @@ -20,11 +20,10 @@
use Zikula\ProfileBundle\Helper\GravatarHelper;
use Zikula\ProfileBundle\ProfileConstant;
use Zikula\UsersBundle\Entity\User;
use Zikula\UsersBundle\ProfileBundle\ProfileBundleInterface;
use Zikula\UsersBundle\Repository\UserRepositoryInterface;
use function Symfony\Component\String\s;

class ProfileBundleBridge implements ProfileBundleInterface
class ProfileBundleBridge
{
public function __construct(
private readonly RouterInterface $router,
Expand Down
14 changes: 2 additions & 12 deletions src/system/ProfileBundle/Menu/ExtensionMenu.php
Expand Up @@ -15,14 +15,9 @@

use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use Zikula\ThemeBundle\ExtensionMenu\AbstractExtensionMenu;
use Zikula\UsersBundle\ProfileBundle\ProfileBundleCollector;

class ExtensionMenu extends AbstractExtensionMenu
{
public function __construct(private readonly ProfileBundleCollector $profileBundleCollector)
{
}

protected function getAdmin(): iterable
{
yield MenuItem::linktoRoute('Property list', 'fas fa-list', 'zikulaprofilebundle_property_listproperties')
Expand All @@ -43,14 +38,9 @@ protected function getUser(): iterable

protected function getAccount(): iterable
{
// do not show any account links if Profile is not the Profile manager
if ($this->profileBundleCollector->getSelectedName() !== $this->getBundleName()) {
return null;
}

yield MenuItem::linktoRoute('Profile', 'fas fa-user', 'zikulaprofilebundle_profile_display', [
yield MenuItem::linktoRoute('Profile', 'fas fa-user', 'zikulaprofilebundle_profile_display'/*, [
'uid' => $this->currentUserApi->get('uid'),
])
]*/)
->setPermission('IS_AUTHENTICATED');
}

Expand Down
Expand Up @@ -11,12 +11,12 @@
* file that was distributed with this source code.
*/

namespace Zikula\UsersBundle\Twig\Extension;
namespace Zikula\ProfileBundle\Twig\Extension;

use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Zikula\UsersBundle\Twig\Runtime\ProfileRuntime;
use Zikula\ProfileBundle\Twig\Runtime\ProfileRuntime;

class ProfileExtension extends AbstractExtension
{
Expand Down
Expand Up @@ -11,21 +11,21 @@
* file that was distributed with this source code.
*/

namespace Zikula\UsersBundle\Twig\Runtime;
namespace Zikula\ProfileBundle\Twig\Runtime;

use InvalidArgumentException;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Extension\RuntimeExtensionInterface;
use Zikula\ProfileBundle\Bridge\ProfileBundleBridge;
use Zikula\UsersBundle\Entity\User;
use Zikula\UsersBundle\ProfileBundle\ProfileBundleCollector;
use Zikula\UsersBundle\Repository\UserRepositoryInterface;
use function Symfony\Component\String\s;

class ProfileRuntime implements RuntimeExtensionInterface
{
public function __construct(
private readonly ProfileBundleBridge $profile,
private readonly UserRepositoryInterface $userRepository,
private readonly ProfileBundleCollector $profileBundleCollector,
private readonly TranslatorInterface $translator
) {
}
Expand All @@ -37,7 +37,7 @@ public function __construct(
*/
public function getUserAvatar($userId = 0, array $parameters = []): string
{
return $this->profileBundleCollector->getSelected()->getAvatar($userId, $parameters);
return $this->profile->getAvatar($userId, $parameters);
}

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ private function determineProfileLink(
return $userId . $userName; // one or the other is empty
}

$userDisplayName = $this->profileBundleCollector->getSelected()->getDisplayName($user->getUid());
$userDisplayName = $this->profile->getDisplayName($user->getUid());
if (!$userDisplayName) {
$userDisplayName = $user->getUname();
}
Expand All @@ -133,7 +133,7 @@ private function determineProfileLink(
} else {
$show = htmlspecialchars($userDisplayName, ENT_QUOTES);
}
$href = $this->profileBundleCollector->getSelected()->getProfileUrl($user->getUid());
$href = $this->profile->getProfileUrl($user->getUid());
if ('#' === $href) {
return $userDisplayName;
}
Expand Down
6 changes: 2 additions & 4 deletions src/system/ProfileBundle/Twig/TwigExtension.php
Expand Up @@ -28,10 +28,8 @@ public function getFilters()
];
}

public function formatPropertyForDisplay(
Property $property,
UserAttribute $attribute
): string {
public function formatPropertyForDisplay(Property $property, UserAttribute $attribute): string
{
$value = $attribute->getValue();
if (empty($value)) {
return $value;
Expand Down
Expand Up @@ -16,24 +16,30 @@
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Translation\TranslatableMessage;
use Zikula\Bundle\CoreBundle\Site\SiteDefinitionInterface;
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuCollector;
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuInterface;
use Zikula\ThemeBundle\Helper\AdminBundleHelper;
use Zikula\ThemeBundle\Helper\AdminCategoryHelper;
use Zikula\ThemeBundle\Helper\UserMenuExtensionHelper;

abstract class AbstractThemedDashboardController extends AbstractDashboardController
{
public function __construct(
protected readonly KernelInterface $kernel,
protected readonly AdminUrlGenerator $adminUrlGenerator,
protected readonly AdminUrlGenerator $urlGenerator,
protected readonly AdminCategoryHelper $adminCategoryHelper,
protected readonly AdminBundleHelper $adminBundleHelper,
protected readonly ExtensionMenuCollector $extensionMenuCollector,
protected readonly UserMenuExtensionHelper $userMenuExtensionHelper,
protected readonly SiteDefinitionInterface $site,
protected readonly array $themeConfig
) {
Expand Down Expand Up @@ -84,6 +90,11 @@ public function configureCrud(): Crud
;
}

public function configureUserMenu(UserInterface $user): UserMenu
{
return $this->userMenuExtensionHelper->configureUserMenu(parent::configureUserMenu($user), $user);
}

public function index(): Response
{
$contentConfig = $this->themeConfig['content'];
Expand All @@ -94,12 +105,12 @@ public function index(): Response

if (null !== $contentConfig['redirect']['crud']) {
// redirect to a CRUD controller page
return $this->redirect($this->adminUrlGenerator->setController($contentConfig['redirect']['crud'])->generateUrl());
return $this->redirect($this->urlGenerator->setController($contentConfig['redirect']['crud'])->generateUrl());
}

if (null !== $contentConfig['redirect']['route']) {
// redirect to a Symfony route
return $this->redirectToRoute($contentConfig['redirect']['route'], $contentConfig['redirect']['route_parameters']);
return $this->redirect($this->urlGenerator->setRoute($contentConfig['redirect']['route'], $contentConfig['redirect']['route_parameters'])->generateUrl());
}

// render EAB welcome page
Expand Down

0 comments on commit 68245a4

Please sign in to comment.