Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 error for Folder URLs without 'URL suffix' #2775

Closed
hamidpeywasti opened this issue Feb 19, 2021 · 2 comments · Fixed by #2784
Closed

404 error for Folder URLs without 'URL suffix' #2775

hamidpeywasti opened this issue Feb 19, 2021 · 2 comments · Fixed by #2784
Labels
Milestone

Comments

@hamidpeywasti
Copy link

hamidpeywasti commented Feb 19, 2021

Affected version(s)

Contao 4.11

Description

After updating to Contao 4.11, Folder URLs return 404 error [when URL's suffix is empty].

https://domain.com => OK
https://domain.com/about => OK
https://domian.com/about/ceo => error 404

When URLs suffix is changed to '/' or '.html' or something else, everything works properly.

https://domain.com/about.html => OK
https://domian.com/about/ceo.html => OK
or
https://domain.com/about/ => OK
https://domian.com/about/ceo/ => OK

Don't matter legacy_routing is false or true.

This website is hosted in Cpanel Server (Couldlinux with Litespeed PHP info). This problem don't occur in my local Contao installtion (php 7.4 and apache v2.4).

@ausi
Copy link
Member

ausi commented Feb 20, 2021

I can confirm this issue. I get an UnusedArgumentsException: Unused arguments: auto_item thrown in

throw new \UnusedArgumentsException('Unused arguments: ' . implode(', ', Input::getUnusedGet()));

@aschempp
Copy link
Member

see #2784

@leofeyer leofeyer linked a pull request Feb 22, 2021 that will close this issue
leofeyer pushed a commit that referenced this issue Mar 3, 2021
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2775

Apparently, `substr('foo', 0, -0)` is empty 🙈

Commits
-------

502a0e0 Correctly sort pages on empty URL suffix
aa5fe3b Merge branch '4.11' into bugfix/folderurl
fritzmg pushed a commit to fritzmg/contao that referenced this issue Mar 4, 2021
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2775

Apparently, `substr('foo', 0, -0)` is empty 🙈

Commits
-------

502a0e0 Correctly sort pages on empty URL suffix
aa5fe3b Merge branch '4.11' into bugfix/folderurl
leofeyer pushed a commit that referenced this issue Mar 4, 2021
Description
-----------

Fixes #2787 ([thread](https://community.contao.org/de/showthread.php?80310-Internal-Server-Error-beim-Dr%C3%BCcken-auf-quot-Auswahl-%C3%A4ndern-quot-bei-der-Weiterleitungsseite&p=540163&viewfull=1#post540163)):

```
TypeError:
preg_replace(): Argument #3 ($subject) must be of type array|string, null given

  at vendor/contao/core-bundle/src/EventListener/DataContainer/ContentCompositionListener.php:107
  at preg_replace()
     (vendor/contao/core-bundle/src/EventListener/DataContainer/ContentCompositionListener.php:107)
  at Contao\CoreBundle\EventListener\DataContainer\ContentCompositionListener->renderPageArticlesOperation()
     (vendor/contao/core-bundle/src/Resources/contao/classes/DataContainer.php:804)
  at Contao\DataContainer->generateButtons()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:4028)
  at Contao\DC_Table->generateTree()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:3628)
  at Contao\DC_Table->treeView()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:353)
  at Contao\DC_Table->showAll()
     (vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php:644)
  at Contao\Backend->getBackendModule()
     (vendor/contao/core-bundle/src/Resources/contao/controllers/BackendMain.php:167)
  at Contao\BackendMain->run()
     (vendor/contao/core-bundle/src/Controller/BackendController.php:48)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor/symfony/http-kernel/HttpKernel.php:158)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/http-kernel/HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (web/index.php:31)
```

Since `$icon` can specifically be null. Not sure why it would be though in this specific instance, but apparently it can happen.

Commits
-------

1f5fa9d check if icon is null
d3f8425 return empty string if href and icon are missing
a6d128a Merge branch '4.11' into fix-content-composition-listener-if-icon-is-null
7fc3159 Update core-bundle/src/EventListener/DataContainer/ContentCompositionListener.php

Co-authored-by: Leo Feyer <github@contao.org>
69243b6 Correctly merge image size _defaults (see #2783)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | -
| Docs PR or issue | -

Currently defining `formats` under the image size `_defaults` is broken. This is because the processed config values of the individual size definitions already contain an empty `formats` array which then wins in  `array_merge`. This PR fixes this problem by giving the values under `_defaults` precedence over empty arrays.

Unfortunately this case was missing from the tests and went unnoticed (added now)…

Commits
-------

b7b7b60 merge _defaults with precedence over empty arrays
990be33 add reference
af36ec2 Merge branch '4.11' into bugfix/image-size-defaults-empty-arrays
aafb762 Suggest using the contao-setup binary with @php prefix (see #2796)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2776 
| Docs PR or issue | -

related contao/managed-edition#57

Commits
-------

b1bd185 suggest using the prefixed contao-setup binary
9cfd8c6 fix accessing undefined variable (see #2806)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #...
| Docs PR or issue | contao/docs#...

Sigh, another one for PHP8.

Fixes 
```
Warning: Undefined array key "breadcrumb"
```
after clicking on the articles selection in the page tree because the `sorting` array does not contain `breadcrumb`.

Commits
-------

36dcf5e fix accessing undefined variable
fdbc6b8 Correctly sort pages if the URL suffix is empty (see #2784)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2775

Apparently, `substr('foo', 0, -0)` is empty 🙈

Commits
-------

502a0e0 Correctly sort pages on empty URL suffix
aa5fe3b Merge branch '4.11' into bugfix/folderurl
f16cbfc Fix accessing Model\Collection instead of Model in ModuleFaqPage (see #2788)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2786 
| Docs PR or issue | -

`$figureBuilder->setMetadata($objFaq->getOverwriteMetadata())` was failing because `$objFaq` is a `Model\Collection` instead of a `Model`. To prevent this rather hard to spot error in the future, I adjusted how we're iterating over the results instead.

Commits
-------

ff2f8b9 iterate over FaqModels instead of operating on Model\Collection
c2934f0 Merge branch '4.11' into bugfix/module-faq-model-collection
51107f0 Handle another illegal array access in the tl_page DCA (see #2794)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes -
| Docs PR or issue | -

This fixes `Warning: Undefined array key "root"` coming from `DCTable` line 3669. This also hardens `tl_page#pastePage()` that will receive an incomplete `$row` by the call in line 3678 and would otherwise produce `Warning: Undefined array key "pid"`.

https://github.com/contao/contao/blob/1873bcc9ea728a08ca8755f6e7251d999d7b316b/core-bundle/src/Resources/contao/drivers/DC_Table.php#L3669-L3690

Commits
-------

7e5b39f handle illegal array access
5ff8b5f simplify expression

Co-authored-by: Leo Feyer <github@contao.org>
aaa71e1 Fix the logout handler in Symfony 5 (see #2818)

Description
-----------

This PR fixes the following error in Contao **4.11.0**:

```
TypeError:
Argument 2 passed to Contao\CoreBundle\Security\Logout\LogoutHandler::logout() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in vendor\symfony\security-bundle\Security\LegacyLogoutHandlerListener.php on line 42

  at vendor\contao\contao\core-bundle\src\Security\Logout\LogoutHandler.php:50
  at Contao\CoreBundle\Security\Logout\LogoutHandler->logout()
     (vendor\symfony\security-bundle\Security\LegacyLogoutHandlerListener.php:42)
  at Symfony\Bundle\SecurityBundle\Security\LegacyLogoutHandlerListener->onLogout()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:270)
  at Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor\symfony\security-http\Firewall\LogoutListener.php:122)
  at Symfony\Component\Security\Http\Firewall\LogoutListener->authenticate()
     (vendor\symfony\security-bundle\Debug\WrappedLazyListener.php:49)
  at Symfony\Bundle\SecurityBundle\Debug\WrappedLazyListener->authenticate()
     (vendor\symfony\security-http\Firewall\AbstractListener.php:26)
  at Symfony\Component\Security\Http\Firewall\AbstractListener->__invoke()
     (vendor\symfony\security-bundle\Debug\TraceableFirewallListener.php:62)
  at Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener->callListeners()
     (vendor\symfony\security-http\Firewall.php:86)
  at Symfony\Component\Security\Http\Firewall->onKernelRequest()
     (vendor\symfony\event-dispatcher\Debug\WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor\symfony\event-dispatcher\Debug\TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (vendor\symfony\http-kernel\HttpKernel.php:133)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor\symfony\http-kernel\HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor\symfony\http-kernel\Kernel.php:195)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (web\index.php:31)
  at require('web\\index.php')
     (web\app.php:4)           
```

**Reproduction**:

1. Create a login form, login page and member.
2. Create a logout page.
3. Log into the front end.
4. Use the link in the menu for the logout.

Apparently the `LogoutEvent` might not contain a `Response` object any more.

Commits
-------

aa5b2e8 fix argument error in Symfony 5
bd06335 Merge branch '4.11' into fix-logout-handler
e1f1e8d Fix an illegal array access in DC_Table when expanding the tree (see #2805)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2797 
| Docs PR or issue | -

I split the PR in two commits:
* one that *only* formats the code so that there is any chance of reviewing this:
a1a16fe
* one that applies the fixes:
9bcedb7

(If you want to, I can collapse the whole thing into a oneline-mega-expression again in a third one…)

Commits
-------

a1a16fe format call
9bcedb7 fix illegal array access
2f22b2f collapse expression
01a9a39 Allow passing an array of IDs to User::isMemberOf() (see #2834)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2753
| Docs PR or issue | -

To fix #2753 (do not show protected pages in the sitemap if there is no front end user or the user groups do not match), I have adjusted the `User::isMemberOf()` method to also accept an array of group IDs. This allows us to greatly simplify other checks as well:

### Current

```php
$blnFeUserLoggedIn = System::getContainer()->get('contao.security.token_checker')->hasFrontendUser();

while ($objCalendar->next())
{
	if ($objCalendar->protected)
	{
		if (!$blnFeUserLoggedIn || !\is_array($this->User->groups))
		{
			continue;
		}

		$groups = StringUtil::deserialize($objCalendar->groups);

		if (empty($groups) || !\is_array($groups) || \count(array_intersect($groups, $this->User->groups)) < 1)
		{
			continue;
		}
	}

	// …
}
```

### New

```php
$user = null;

if (System::getContainer()->get('contao.security.token_checker')->hasFrontendUser())
{
	$user = FrontendUser::getInstance();
}

while ($objCalendar->next())
{
	if ($objCalendar->protected && (!$user || !$user->isMemberOf(StringUtil::deserialize($objCalendar->groups))))
	{
		continue;
	}

	// …
}
```

Commits
-------

9a924c3 Allow passing an array of IDs to User::isMemberOf()
c5c39ae add some unit tests
2db757c Merge branch '4.11' into fix-content-composition-listener-if-icon-is-null
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this issue Apr 6, 2021
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2775

Apparently, `substr('foo', 0, -0)` is empty 🙈

Commits
-------

502a0e0 Correctly sort pages on empty URL suffix
aa5fe3b Merge branch '4.11' into bugfix/folderurl
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this issue Apr 6, 2021
)

Description
-----------

Fixes contao#2787 ([thread](https://community.contao.org/de/showthread.php?80310-Internal-Server-Error-beim-Dr%C3%BCcken-auf-quot-Auswahl-%C3%A4ndern-quot-bei-der-Weiterleitungsseite&p=540163&viewfull=1#post540163)):

```
TypeError:
preg_replace(): Argument contao#3 ($subject) must be of type array|string, null given

  at vendor/contao/core-bundle/src/EventListener/DataContainer/ContentCompositionListener.php:107
  at preg_replace()
     (vendor/contao/core-bundle/src/EventListener/DataContainer/ContentCompositionListener.php:107)
  at Contao\CoreBundle\EventListener\DataContainer\ContentCompositionListener->renderPageArticlesOperation()
     (vendor/contao/core-bundle/src/Resources/contao/classes/DataContainer.php:804)
  at Contao\DataContainer->generateButtons()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:4028)
  at Contao\DC_Table->generateTree()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:3628)
  at Contao\DC_Table->treeView()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:353)
  at Contao\DC_Table->showAll()
     (vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php:644)
  at Contao\Backend->getBackendModule()
     (vendor/contao/core-bundle/src/Resources/contao/controllers/BackendMain.php:167)
  at Contao\BackendMain->run()
     (vendor/contao/core-bundle/src/Controller/BackendController.php:48)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor/symfony/http-kernel/HttpKernel.php:158)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/http-kernel/HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (web/index.php:31)
```

Since `$icon` can specifically be null. Not sure why it would be though in this specific instance, but apparently it can happen.

Commits
-------

1f5fa9d check if icon is null
d3f8425 return empty string if href and icon are missing
a6d128a Merge branch '4.11' into fix-content-composition-listener-if-icon-is-null
7fc3159 Update core-bundle/src/EventListener/DataContainer/ContentCompositionListener.php

Co-authored-by: Leo Feyer <github@contao.org>
69243b6 Correctly merge image size _defaults (see contao#2783)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | -
| Docs PR or issue | -

Currently defining `formats` under the image size `_defaults` is broken. This is because the processed config values of the individual size definitions already contain an empty `formats` array which then wins in  `array_merge`. This PR fixes this problem by giving the values under `_defaults` precedence over empty arrays.

Unfortunately this case was missing from the tests and went unnoticed (added now)…

Commits
-------

b7b7b60 merge _defaults with precedence over empty arrays
990be33 add reference
af36ec2 Merge branch '4.11' into bugfix/image-size-defaults-empty-arrays
aafb762 Suggest using the contao-setup binary with @php prefix (see contao#2796)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2776
| Docs PR or issue | -

related contao/managed-edition#57

Commits
-------

b1bd185 suggest using the prefixed contao-setup binary
9cfd8c6 fix accessing undefined variable (see contao#2806)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #...
| Docs PR or issue | contao/docs#...

Sigh, another one for PHP8.

Fixes
```
Warning: Undefined array key "breadcrumb"
```
after clicking on the articles selection in the page tree because the `sorting` array does not contain `breadcrumb`.

Commits
-------

36dcf5e fix accessing undefined variable
fdbc6b8 Correctly sort pages if the URL suffix is empty (see contao#2784)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2775

Apparently, `substr('foo', 0, -0)` is empty 🙈

Commits
-------

502a0e0 Correctly sort pages on empty URL suffix
aa5fe3b Merge branch '4.11' into bugfix/folderurl
f16cbfc Fix accessing Model\Collection instead of Model in ModuleFaqPage (see contao#2788)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2786
| Docs PR or issue | -

`$figureBuilder->setMetadata($objFaq->getOverwriteMetadata())` was failing because `$objFaq` is a `Model\Collection` instead of a `Model`. To prevent this rather hard to spot error in the future, I adjusted how we're iterating over the results instead.

Commits
-------

ff2f8b9 iterate over FaqModels instead of operating on Model\Collection
c2934f0 Merge branch '4.11' into bugfix/module-faq-model-collection
51107f0 Handle another illegal array access in the tl_page DCA (see contao#2794)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes -
| Docs PR or issue | -

This fixes `Warning: Undefined array key "root"` coming from `DCTable` line 3669. This also hardens `tl_page#pastePage()` that will receive an incomplete `$row` by the call in line 3678 and would otherwise produce `Warning: Undefined array key "pid"`.

https://github.com/contao/contao/blob/1873bcc9ea728a08ca8755f6e7251d999d7b316b/core-bundle/src/Resources/contao/drivers/DC_Table.php#L3669-L3690

Commits
-------

7e5b39f handle illegal array access
5ff8b5f simplify expression

Co-authored-by: Leo Feyer <github@contao.org>
aaa71e1 Fix the logout handler in Symfony 5 (see contao#2818)

Description
-----------

This PR fixes the following error in Contao **4.11.0**:

```
TypeError:
Argument 2 passed to Contao\CoreBundle\Security\Logout\LogoutHandler::logout() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in vendor\symfony\security-bundle\Security\LegacyLogoutHandlerListener.php on line 42

  at vendor\contao\contao\core-bundle\src\Security\Logout\LogoutHandler.php:50
  at Contao\CoreBundle\Security\Logout\LogoutHandler->logout()
     (vendor\symfony\security-bundle\Security\LegacyLogoutHandlerListener.php:42)
  at Symfony\Bundle\SecurityBundle\Security\LegacyLogoutHandlerListener->onLogout()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:270)
  at Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor\symfony\security-http\Firewall\LogoutListener.php:122)
  at Symfony\Component\Security\Http\Firewall\LogoutListener->authenticate()
     (vendor\symfony\security-bundle\Debug\WrappedLazyListener.php:49)
  at Symfony\Bundle\SecurityBundle\Debug\WrappedLazyListener->authenticate()
     (vendor\symfony\security-http\Firewall\AbstractListener.php:26)
  at Symfony\Component\Security\Http\Firewall\AbstractListener->__invoke()
     (vendor\symfony\security-bundle\Debug\TraceableFirewallListener.php:62)
  at Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener->callListeners()
     (vendor\symfony\security-http\Firewall.php:86)
  at Symfony\Component\Security\Http\Firewall->onKernelRequest()
     (vendor\symfony\event-dispatcher\Debug\WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor\symfony\event-dispatcher\EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor\symfony\event-dispatcher\Debug\TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (vendor\symfony\http-kernel\HttpKernel.php:133)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor\symfony\http-kernel\HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor\symfony\http-kernel\Kernel.php:195)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (web\index.php:31)
  at require('web\\index.php')
     (web\app.php:4)
```

**Reproduction**:

1. Create a login form, login page and member.
2. Create a logout page.
3. Log into the front end.
4. Use the link in the menu for the logout.

Apparently the `LogoutEvent` might not contain a `Response` object any more.

Commits
-------

aa5b2e8 fix argument error in Symfony 5
bd06335 Merge branch '4.11' into fix-logout-handler
e1f1e8d Fix an illegal array access in DC_Table when expanding the tree (see contao#2805)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2797
| Docs PR or issue | -

I split the PR in two commits:
* one that *only* formats the code so that there is any chance of reviewing this:
contao@a1a16fe
* one that applies the fixes:
contao@9bcedb7

(If you want to, I can collapse the whole thing into a oneline-mega-expression again in a third one…)

Commits
-------

a1a16fe format call
9bcedb7 fix illegal array access
2f22b2f collapse expression
01a9a39 Allow passing an array of IDs to User::isMemberOf() (see contao#2834)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2753
| Docs PR or issue | -

To fix contao#2753 (do not show protected pages in the sitemap if there is no front end user or the user groups do not match), I have adjusted the `User::isMemberOf()` method to also accept an array of group IDs. This allows us to greatly simplify other checks as well:

### Current

```php
$blnFeUserLoggedIn = System::getContainer()->get('contao.security.token_checker')->hasFrontendUser();

while ($objCalendar->next())
{
	if ($objCalendar->protected)
	{
		if (!$blnFeUserLoggedIn || !\is_array($this->User->groups))
		{
			continue;
		}

		$groups = StringUtil::deserialize($objCalendar->groups);

		if (empty($groups) || !\is_array($groups) || \count(array_intersect($groups, $this->User->groups)) < 1)
		{
			continue;
		}
	}

	// …
}
```

### New

```php
$user = null;

if (System::getContainer()->get('contao.security.token_checker')->hasFrontendUser())
{
	$user = FrontendUser::getInstance();
}

while ($objCalendar->next())
{
	if ($objCalendar->protected && (!$user || !$user->isMemberOf(StringUtil::deserialize($objCalendar->groups))))
	{
		continue;
	}

	// …
}
```

Commits
-------

9a924c3 Allow passing an array of IDs to User::isMemberOf()
c5c39ae add some unit tests
2db757c Merge branch '4.11' into fix-content-composition-listener-if-icon-is-null
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants