-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
97 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
vendor/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; | ||
use Symplify\EasyCodingStandard\Config\ECSConfig; | ||
|
||
return static function (ECSConfig $ecsConfig): void { | ||
$ecsConfig->paths([ | ||
__DIR__ . '/src', | ||
]); | ||
|
||
$ecsConfig->import(__DIR__.'/vendor/contao/easy-coding-standard/config/contao.php'); | ||
|
||
$services = $ecsConfig->services(); | ||
|
||
$services | ||
->set(HeaderCommentFixer::class) | ||
->call('configure', [[ | ||
'header' => "This file is part of richardhj/contao-knp-menu.\n\n(c) Richard Henkenjohann <[email protected]>\n\n@license MIT", | ||
]]) | ||
; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,9 @@ | |
/* | ||
* This file is part of richardhj/contao-knp-menu. | ||
* | ||
* Copyright (c) 2020-2021 Richard Henkenjohann | ||
* (c) Richard Henkenjohann <[email protected]> | ||
* | ||
* @package richardhj/contao-knp-menu | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2020-2021 Richard Henkenjohann | ||
* @license MIT | ||
* @license MIT | ||
*/ | ||
|
||
namespace Richardhj\ContaoKnpMenuBundle\ContaoManager; | ||
|
@@ -27,7 +24,7 @@ class Plugin implements BundlePluginInterface | |
/** | ||
* Gets a list of autoload configurations for this bundle. | ||
* | ||
* @return ConfigInterface[] | ||
* @return array<ConfigInterface> | ||
*/ | ||
public function getBundles(ParserInterface $parser): array | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,9 @@ | |
/* | ||
* This file is part of richardhj/contao-knp-menu. | ||
* | ||
* Copyright (c) 2020-2021 Richard Henkenjohann | ||
* (c) Richard Henkenjohann <[email protected]> | ||
* | ||
* @package richardhj/contao-knp-menu | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2020-2021 Richard Henkenjohann | ||
* @license MIT | ||
* @license MIT | ||
*/ | ||
|
||
namespace Richardhj\ContaoKnpMenuBundle\DependencyInjection; | ||
|
@@ -25,7 +22,7 @@ class RichardhjContaoKnpMenuExtension extends Extension | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yml'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,9 @@ | |
/* | ||
* This file is part of richardhj/contao-knp-menu. | ||
* | ||
* Copyright (c) 2020-2021 Richard Henkenjohann | ||
* (c) Richard Henkenjohann <[email protected]> | ||
* | ||
* @package richardhj/contao-knp-menu | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2020-2021 Richard Henkenjohann | ||
* @license MIT | ||
* @license MIT | ||
*/ | ||
|
||
namespace Richardhj\ContaoKnpMenuBundle\Menu; | ||
|
@@ -31,21 +28,17 @@ | |
|
||
class MenuBuilder | ||
{ | ||
private FactoryInterface $factory; | ||
private RequestStack $requestStack; | ||
private ContaoFramework $framework; | ||
private FactoryInterface $factory; | ||
private RequestStack $requestStack; | ||
private ContaoFramework $framework; | ||
private EventDispatcherInterface $dispatcher; | ||
|
||
public function __construct( | ||
FactoryInterface $factory, | ||
RequestStack $requestStack, | ||
ContaoFramework $framework, | ||
EventDispatcherInterface $dispatcher | ||
) { | ||
$this->factory = $factory; | ||
public function __construct(FactoryInterface $factory, RequestStack $requestStack, ContaoFramework $framework, EventDispatcherInterface $dispatcher) | ||
{ | ||
$this->factory = $factory; | ||
$this->requestStack = $requestStack; | ||
$this->framework = $framework; | ||
$this->dispatcher = $dispatcher; | ||
$this->framework = $framework; | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null, array $options = []): ItemInterface | ||
|
@@ -54,10 +47,10 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null, | |
return $root; | ||
} | ||
|
||
$pageAdapter = $this->framework->getAdapter(PageModel::class); | ||
$pageAdapter = $this->framework->getAdapter(PageModel::class); | ||
|
||
$groups = []; | ||
$request = $this->requestStack->getCurrentRequest(); | ||
$groups = []; | ||
$request = $this->requestStack->getCurrentRequest(); | ||
$requestPage = $request->attributes->get('pageModel'); | ||
|
||
if (is_numeric($requestPage)) { | ||
|
@@ -66,6 +59,7 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null, | |
|
||
/** @var FrontendUser $user */ | ||
$user = $this->framework->createInstance(FrontendUser::class); | ||
|
||
if ($user->id) { | ||
$groups = $user->groups; | ||
} | ||
|
@@ -86,13 +80,17 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null, | |
|
||
// Check whether there will be subpages | ||
if ($page->subpages > 0) { | ||
|
||
$level++; | ||
++$level; | ||
$childRecords = Database::getInstance()->getChildRecords($page->id, 'tl_page'); | ||
|
||
$item->setDisplayChildren(false); | ||
if (!$options['showLevel'] || $options['showLevel'] >= $level || ( | ||
!$options['hardLimit'] && ($requestPage->id == $page->id || \in_array($requestPage->id, $childRecords)))) { | ||
|
||
if ( | ||
!$options['showLevel'] || $options['showLevel'] >= $level || | ||
( | ||
!$options['hardLimit'] && ($requestPage->id === $page->id || \in_array($requestPage->id, $childRecords, true)) | ||
) | ||
) { | ||
$item->setDisplayChildren(true); | ||
} | ||
|
||
|
@@ -146,7 +144,7 @@ private function getPages(int $pid, array $options): ?Collection | |
|
||
$ids = StringUtil::deserialize($options['pages'], true); | ||
|
||
return PageModel::findPublishedRegularWithoutGuestsByIds($ids, ['includeRoot'=>true]); | ||
return PageModel::findPublishedRegularWithoutGuestsByIds($ids, ['includeRoot' => true]); | ||
} | ||
|
||
private function populateMenuItem(MenuItem $item, ?PageModel $requestPage, PageModel $page, $href): MenuItem | ||
|
@@ -160,15 +158,17 @@ private function populateMenuItem(MenuItem $item, ?PageModel $requestPage, PageM | |
$path = current(explode('?', Environment::get('request'), 2)); | ||
|
||
// Active page | ||
if ($href === $path | ||
&& ((null !== $requestPage && $requestPage->id === $page->id) || ('forward' === $page->type && $requestPage->id === $page->jumpTo))) { | ||
if ( | ||
$href === $path | ||
&& ((null !== $requestPage && $requestPage->id === $page->id) || ('forward' === $page->type && $requestPage->id === $page->jumpTo)) | ||
) { | ||
$extra['isActive'] = true; | ||
$extra['isTrail'] = false; | ||
$extra['isTrail'] = false; | ||
|
||
$item->setCurrent(true); | ||
} else { | ||
$extra['isActive'] = false; | ||
$extra['isTrail'] = $trail; | ||
$extra['isTrail'] = $trail; | ||
} | ||
|
||
$extra['class'] = trim($page->cssClass); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,9 @@ | |
/* | ||
* This file is part of richardhj/contao-knp-menu. | ||
* | ||
* Copyright (c) 2020-2021 Richard Henkenjohann | ||
* (c) Richard Henkenjohann <[email protected]> | ||
* | ||
* @package richardhj/contao-knp-menu | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2020-2021 Richard Henkenjohann | ||
* @license MIT | ||
* @license MIT | ||
*/ | ||
|
||
namespace Richardhj\ContaoKnpMenuBundle\Menu; | ||
|
@@ -26,23 +23,23 @@ | |
class NavigationModuleProvider implements MenuProviderInterface | ||
{ | ||
private FactoryInterface $factory; | ||
private MenuBuilder $builder; | ||
private ContaoFramework $framework; | ||
private RequestStack $requestStack; | ||
private MenuBuilder $builder; | ||
private ContaoFramework $framework; | ||
private RequestStack $requestStack; | ||
|
||
public function __construct(FactoryInterface $factory, MenuBuilder $builder, ContaoFramework $framework, RequestStack $requestStack) | ||
{ | ||
$this->factory = $factory; | ||
$this->builder = $builder; | ||
$this->framework = $framework; | ||
$this->factory = $factory; | ||
$this->builder = $builder; | ||
$this->framework = $framework; | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
public function get($name, array $options = []): ItemInterface | ||
{ | ||
$request = $this->requestStack->getCurrentRequest(); | ||
$request = $this->requestStack->getCurrentRequest(); | ||
$moduleAdapter = $this->framework->getAdapter(ModuleModel::class); | ||
$pageAdapter = $this->framework->getAdapter(PageModel::class); | ||
$pageAdapter = $this->framework->getAdapter(PageModel::class); | ||
|
||
/** @var ModuleModel $module */ | ||
if (null === $module = $moduleAdapter->findBy('menuAlias', $name)) { | ||
|
@@ -55,7 +52,7 @@ public function get($name, array $options = []): ItemInterface | |
$currentPage = $pageAdapter->findByPk($currentPage); | ||
} | ||
|
||
$menu = $this->factory->createItem('root'); | ||
$menu = $this->factory->createItem('root'); | ||
$options = array_merge($module->row(), $options); | ||
|
||
// Set the trail and level | ||
|
@@ -66,16 +63,18 @@ public function get($name, array $options = []): ItemInterface | |
throw new \RuntimeException('Current request does not have a page model. Please define the root page in the navigation module.'); | ||
} else { | ||
$trail = $currentPage->trail; | ||
$level = ($options['levelOffset'] > 0) ? $options['levelOffset'] : 0; | ||
$level = $options['levelOffset'] > 0 ? $options['levelOffset'] : 0; | ||
} | ||
|
||
// Overwrite the domain and language if the reference page belongs to a different root page (see #3765) | ||
if ($options['defineRoot'] | ||
if ( | ||
$options['defineRoot'] | ||
&& $options['rootPage'] > 0 | ||
&& (null !== $rootPage = PageModel::findWithDetails($options['rootPage'])) | ||
&& $rootPage->rootId !== $currentPage->rootId | ||
&& $rootPage->domain | ||
&& $rootPage->domain !== $currentPage->domain) { | ||
&& $rootPage->domain !== $currentPage->domain | ||
) { | ||
$host = $rootPage->domain; | ||
} | ||
|
||
|
@@ -85,7 +84,7 @@ public function get($name, array $options = []): ItemInterface | |
public function has($name, array $options = []): bool | ||
{ | ||
$adapter = $this->framework->getAdapter(ModuleModel::class); | ||
$module = $adapter->findBy('menuAlias', $name); | ||
$module = $adapter->findBy('menuAlias', $name); | ||
|
||
return null !== $module; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,9 @@ | |
/* | ||
* This file is part of richardhj/contao-knp-menu. | ||
* | ||
* Copyright (c) 2020-2021 Richard Henkenjohann | ||
* (c) Richard Henkenjohann <[email protected]> | ||
* | ||
* @package richardhj/contao-knp-menu | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2020-2021 Richard Henkenjohann | ||
* @license MIT | ||
* @license MIT | ||
*/ | ||
|
||
use Contao\CoreBundle\DataContainer\PaletteManipulator; | ||
|
@@ -22,8 +19,8 @@ | |
; | ||
|
||
$GLOBALS['TL_DCA']['tl_module']['fields']['menuAlias'] = [ | ||
'exclude' => true, | ||
'exclude' => true, | ||
'inputType' => 'text', | ||
'eval' => ['maxlength' => 255, 'tl_class' => 'w50 clr', 'unique' => true], | ||
'sql' => "varchar(255) NOT NULL default ''", | ||
'eval' => ['maxlength' => 255, 'tl_class' => 'w50 clr', 'unique' => true], | ||
'sql' => "varchar(255) NOT NULL default ''", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,9 @@ | |
/* | ||
* This file is part of richardhj/contao-knp-menu. | ||
* | ||
* Copyright (c) 2020-2021 Richard Henkenjohann | ||
* (c) Richard Henkenjohann <[email protected]> | ||
* | ||
* @package richardhj/contao-knp-menu | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2020-2021 Richard Henkenjohann | ||
* @license MIT | ||
* @license MIT | ||
*/ | ||
|
||
namespace Richardhj\ContaoKnpMenuBundle; | ||
|