<?php
namespace App\Component\AdminMenu\EventSubscriber;
use App\Component\AdminMenu\Event\AbstractBuildMenuEvent;
use App\Component\AdminMenu\MenuBuilder;
use App\Component\UserRole\Permission\UserRolePermission;
use App\Dto\MenuItem;
use App\Entity\Background;
use App\Entity\Blog;
use App\Entity\Calendar;
use App\Entity\CustomTranslation;
use App\Entity\DynamicForm;
use App\Entity\Event;
use App\Entity\EventAttribute;
use App\Entity\Faq;
use App\Entity\Gallery;
use App\Entity\GdprStatement;
use App\Entity\Grid;
use App\Entity\HarverExperience;
use App\Entity\Hero;
use App\Entity\Invoice;
use App\Entity\Location;
use App\Entity\LogoSlider;
use App\Entity\MegaMenuItem;
use App\Entity\MultiMedia;
use App\Entity\MultiPoster;
use App\Entity\Order;
use App\Entity\OrderFields;
use App\Entity\Page;
use App\Entity\Person;
use App\Entity\Portfolio;
use App\Entity\Product;
use App\Entity\QR;
use App\Entity\Review;
use App\Entity\Sample;
use App\Entity\SiteBlock;
use App\Entity\SocialWall;
use App\Entity\Testimonial;
use App\Entity\USP;
use App\Entity\VacancyUsp;
use App\Entity\WebServiceApiKey;
use App\EventListener\FeatureFlagListener;
use App\Form\Setting\ThemeSettingType;
use Knp\Menu\ItemInterface;
class ContentMenuSubscriber extends AbstractMenuBuildEventSubscriber
{
protected static int $priority = -10;
/**
* @throws \Exception
*/
public function buildMenu(AbstractBuildMenuEvent $event)
{
$menuBuilder = $this->getMenuBuilder($event->getMenu());
$menuBuilder->addMainItem('Content', 'fal fa-copy');
/** @var ItemInterface $contentItem */
$contentItem = $menuBuilder->getCurrentContext();
$menuBuilder->addOverlay()
->addSection('Manage content');
$contentItemContainer = $menuBuilder->getCurrentContext();
$contentDto = new MenuItem($contentItem, $contentItemContainer);
$this->addPagesMenu($menuBuilder);
$this->addBlogMenu($menuBuilder);
$this->addTestimonialsMenu($menuBuilder);
$this->addUspMenu($menuBuilder);
$this->addMediaMenu($menuBuilder);
$this->addFAQMenu($menuBuilder);
$this->addEventMenu($menuBuilder);
$this->addPortfolioMenu($menuBuilder);
$this->addReviewsMenu($menuBuilder);
$this->addEcommerceMenu($menuBuilder);
$this->addHarverMenu($menuBuilder);
$this->addPersonsMenu($menuBuilder);
$this->addMiscellaneousMenu($menuBuilder);
$contentDto->close();
}
private function addPagesMenu(MenuBuilder $menuBuilder)
{
$menuBuilder->addColumn('Pages', 'fal fa-copy');
/** @var ItemInterface $contentItem */
$contentItem = $menuBuilder->getCurrentContext();
$contentDto = new MenuItem($contentItem);
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Page::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_PAGES])
) {
$menuBuilder
->addItem('Create page', 'page_create')
->addItem('View menu', 'pages')
->addItem('Deleted', 'admin_page_deleted')
->addItem('admin.menu.pages_attributes', 'admin_page_attribute_index');
}
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, ThemeSettingType::class]])) {
$menuBuilder
->addItem('theme.settings', 'admin_settings', ['type' => 'Theme'])
;
}
$menuBuilder->end();
$contentDto->close();
}
private function addBlogMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Blog::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_BLOG])
) {
$menuBuilder
->addColumn('Blogs', 'fal fa-newspaper')
->addItem('Create article', 'blog_create')
->addItem('View articles', 'admin_blogs')
->addItem('Categories', 'admin_categories')
->addItem('admin.menu.article_attributes', 'admin_blog_attribute_index')
->end();
}
}
private function addTestimonialsMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Testimonial::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_TESTIMONIAL])
) {
$menuBuilder
->addColumn('Testimonials', 'fal fa-comments')
->addItem('Create testimonial', 'admin_testimonial_create')
->addItem('View testimonials', 'admin_testimonials')
->addItem('Testimonial categories', 'admin_testimonial_categories')
->addItem('View testimonial attributes', 'admin_testimonial_attribute_index')
->end();
}
}
private function addUspMenu(MenuBuilder $menuBuilder)
{
if (
(
!$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, USP::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, VacancyUsp::class]])
)
|| !$this->checkFeatures([FeatureFlagListener::FEATURE_USP, FeatureFlagListener::FEATURE_VACANCY_USPS])
) {
return;
}
$menuBuilder
->addColumn("USP's", 'fal fa-check-circle');
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, USP::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_USP])
) {
$menuBuilder
->addItem('Create USP', 'admin_usp_create')
->addItem("View USP's", 'admin_usps')
->addItem('Categories', 'admin_option_value_usps');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, VacancyUsp::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_VACANCY_USPS])
) {
$menuBuilder
->addItem("Vacancy USP's", 'admin_vacancy_usps');
}
$menuBuilder->end();
}
private function addMediaMenu(MenuBuilder $menuBuilder)
{
if (
(
!$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Gallery::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, MultiMedia::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, LogoSlider::class]])
)
|| !$this->checkFeatures(
[
FeatureFlagListener::FEATURE_GALLERY,
FeatureFlagListener::FEATURE_MULTI_MEDIA,
FeatureFlagListener::FEATURE_LOGO_SLIDER,
]
)
) {
return;
}
$menuBuilder
->addColumn('Media', 'fal fa-images');
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, MultiMedia::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_MULTI_MEDIA])
) {
$menuBuilder
->addItem('Create multimedia', 'admin_multi_media_create')
->addItem('View multimedia', 'admin_multi_media_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Gallery::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_GALLERY])
) {
$menuBuilder
->addItem('Media gallery', 'admin_content_gallery_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, LogoSlider::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_LOGO_SLIDER])
) {
$menuBuilder
->addItem('Logo sliders', 'admin_logoslider');
}
$menuBuilder->end();
}
private function addFAQMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Faq::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_FAQ])
) {
$menuBuilder
->addColumn('FAQ', 'fal fa-question')
->addItem('Create FAQ', 'admin_faq_create')
->addItem('View FAQs', 'admin_faqs')
->addItem('FAQ categories', 'admin_faqs_categories')
->end();
}
}
private function addEventMenu(MenuBuilder $menuBuilder)
{
if (
(
!$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Event::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Location::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, EventAttribute::class]])
)
|| !$this->checkFeatures(
[
FeatureFlagListener::FEATURE_EVENTS,
FeatureFlagListener::FEATURE_LOCATIONS,
]
)
) {
return;
}
$menuBuilder->addColumn('Events', 'fal fa-calendar-star');
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Event::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_EVENTS])
) {
$menuBuilder
->addItem('Create event', 'event_create')
->addItem('View events', 'admin_event')
->addItem('Event registrations', 'admin_registrations')
->addItem('Event categories', 'admin_event_categories')
->addItem('Searchfilters', 'admin_event_search_filter_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Location::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_LOCATIONS])
) {
$menuBuilder
->addItem('Locations', 'admin_event_location');
}
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, EventAttribute::class]])) {
$menuBuilder
->addItem('Event attributes', 'admin_event_attribute_index');
}
$menuBuilder->end();
}
private function addPortfolioMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Portfolio::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_PORTFOLIO])
) {
$menuBuilder
->addColumn('Portfolio', 'fal fa-clone')
->addItem('Create portfolio item', 'admin_portfolio_create')
->addItem('View portfolio', 'admin_portfolio')
->end();
}
}
private function addReviewsMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Review::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_REVIEW])
) {
$menuBuilder
->addColumn('Reviews', 'fal fa-star')
->addItem('View reviews', 'admin_review')
->addItem('Review form', 'admin_review_form')
->end();
}
}
private function addEcommerceMenu(MenuBuilder $menuBuilder)
{
if (
(
!$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Product::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Sample::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Order::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, OrderFields::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Invoice::class]])
)
|| !$this->checkFeatures(
[
FeatureFlagListener::FEATURE_PRODUCT,
FeatureFlagListener::FEATURE_SAMPLE,
FeatureFlagListener::FEATURE_ORDER,
FeatureFlagListener::FEATURE_ORDER_FIELDS,
FeatureFlagListener::FEATURE_INVOICE,
FeatureFlagListener::FEATURE_SHOPPING_ASSISTANT,
]
)
) {
return;
}
$menuBuilder->addColumn('E-commerce', 'fal fa-box-open');
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Product::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_PRODUCT])
) {
$menuBuilder
->addItem('Products', 'admin_product');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Sample::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_SAMPLE])
) {
$menuBuilder
->addItem('Samples', 'admin_samples');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Order::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_ORDER])
) {
$menuBuilder
->addItem('View orders', 'admin_order_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, OrderFields::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_ORDER_FIELDS])
) {
$menuBuilder
->addItem('Order form', 'order_fields_edit');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Invoice::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_INVOICE])
) {
$menuBuilder
->addItem('Invoices', 'admin_invoice_index');
}
if ($this->checkFeatures([FeatureFlagListener::FEATURE_SHOPPING_ASSISTANT])) {
$menuBuilder
->addItem('Shopping assistant questions', 'admin_shopping_assistant_question_overview')
->addItem('Shopping assistant answers', 'admin_shopping_assistant_answer_overview');
}
$menuBuilder->end();
}
private function addHarverMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, HarverExperience::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_HARVER])
) {
$menuBuilder
->addColumn('Harver', 'fal fa-chart-network')
->addItem('Experiences', 'admin_harver_experience_index')
->end();
}
}
private function addMiscellaneousMenu(MenuBuilder $menuBuilder)
{
if (
(
!$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, SiteBlock::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Hero::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, MegaMenuItem::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Grid::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Background::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, QR::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, MultiPoster::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, WebServiceApiKey::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, GdprStatement::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, CustomTranslation::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, DynamicForm::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, SocialWall::class]])
&& !$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Calendar::class]])
)
|| !$this->checkFeatures(
[
FeatureFlagListener::FEATURE_SITE_BLOCKS,
FeatureFlagListener::FEATURE_HERO,
FeatureFlagListener::FEATURE_MEGA_MENU,
FeatureFlagListener::FEATURE_GRID,
FeatureFlagListener::FEATURE_BACKGROUND,
FeatureFlagListener::FEATURE_QR,
FeatureFlagListener::FEATURE_WEBSERVICE,
FeatureFlagListener::FEATURE_GDPR,
FeatureFlagListener::FEATURE_CUSTOM_TRANSLATIONS,
FeatureFlagListener::FEATURE_FORM_BUILDER,
FeatureFlagListener::FEATURE_SOCIAL_WALL,
FeatureFlagListener::FEATURE_CALENDAR,
]
)
) {
return;
}
$menuBuilder->addColumn('Other', 'fal fa-globe');
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, CustomTranslation::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_CUSTOM_TRANSLATIONS])
) {
$menuBuilder->addItem('Translations', 'admin_custom_translation_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, SiteBlock::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_SITE_BLOCKS])
) {
$menuBuilder->addItem('Site blocks', 'admin_siteblocks_overview');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Hero::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_HERO])
) {
$menuBuilder->addItem('Hero', 'admin_hero_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, MegaMenuItem::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_MEGA_MENU])
) {
$menuBuilder->addItem('Mega menu', 'admin_mega_menu');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Grid::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_GRID])
) {
$menuBuilder->addItem('Grid', 'grid_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Background::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_BACKGROUND])
) {
$menuBuilder->addItem('Background', 'admin_background');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, QR::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_QR])
) {
$menuBuilder->addItem('QR links', 'admin_qr_index');
}
if ($this->checkFeatures([FeatureFlagListener::FEATURE_WEBSERVICE])) {
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, MultiPoster::class]])
) {
$menuBuilder->addItem('Web service', 'admin_multiposters');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, WebServiceApiKey::class]])
) {
$menuBuilder->addItem('API keys', 'admin_webserviceapikeys');
}
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, GdprStatement::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_GDPR])
) {
$menuBuilder->addItem('GDPR Statements', 'admin_gdpr_statement_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, DynamicForm::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_FORM_BUILDER])
) {
$menuBuilder->addItem('forms.overview', 'admin_forms');
}
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, SocialWall::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_SOCIAL_WALL])
) {
$menuBuilder->addItem('social_walls', 'admin_social_wall');
}
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Calendar::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_CALENDAR])
) {
$menuBuilder->addItem('Calendars', 'admin_calendar_index');
}
$menuBuilder->end();
}
private function addPersonsMenu(MenuBuilder $menuBuilder)
{
if (
$this->hasAccess([[UserRolePermission::MASK_VIEW, Person::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_PERSON])
) {
$menuBuilder->addColumn('Persons', 'fal fa-user-circle');
$menuBuilder->addItem('Create person', 'admin_person_create');
$menuBuilder->addItem('View persons', 'admin_persons');
$menuBuilder->end();
}
}
}