Skip to content

Commit 808ed4e

Browse files
authored
Merge pull request #677 from contao-community-alliance/hotfix/fix_filepicker_overrideall
Fix filepicker overrideall
2 parents 76c28b0 + c60a08f commit 808ed4e

5 files changed

Lines changed: 54 additions & 23 deletions

File tree

src/Contao/View/Contao2BackendView/ActionHandler/MultipleHandler/SelectPropertyAllHandler.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of contao-community-alliance/dc-general.
55
*
6-
* (c) 2013-2024 Contao Community Alliance.
6+
* (c) 2013-2025 Contao Community Alliance.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -13,7 +13,7 @@
1313
* @package contao-community-alliance/dc-general
1414
* @author Sven Baumann <baumann.sv@gmail.com>
1515
* @author Ingolf Steinhardt <info@e-spin.de>
16-
* @copyright 2013-2024 Contao Community Alliance.
16+
* @copyright 2013-2025 Contao Community Alliance.
1717
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0
1818
* @filesource
1919
*/
@@ -416,7 +416,14 @@ protected function renderTemplate(ContaoBackendViewTemplate $template, Environme
416416
(null !== $template->get('action'))
417417
&& (false !== \strpos($template->get('action'), 'select=properties'))
418418
) {
419-
$template->set('action', \str_replace('select=properties', 'select=edit', $template->get('action')));
419+
$template->set(
420+
'action',
421+
\str_replace(
422+
'select=properties',
423+
'select=' . ($inputProvider->getParameter('mode') ?? 'edit'),
424+
$template->get('action')
425+
)
426+
);
420427
}
421428

422429
if (\count($this->messages) > 0) {

src/Contao/View/Contao2BackendView/BaseView.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of contao-community-alliance/dc-general.
55
*
6-
* (c) 2013-2024 Contao Community Alliance.
6+
* (c) 2013-2025 Contao Community Alliance.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -19,7 +19,7 @@
1919
* @author Martin Treml <github@r2pi.net>
2020
* @author Sven Baumann <baumann.sv@gmail.com>
2121
* @author Ingolf Steinhardt <info@e-spin.de>
22-
* @copyright 2013-2024 Contao Community Alliance.
22+
* @copyright 2013-2025 Contao Community Alliance.
2323
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
2424
* @filesource
2525
*/
@@ -708,21 +708,21 @@ private function findOriginalPropertyByModelId(?string $propertyName): ?Property
708708

709709
$selectAction = $inputProvider->getParameter('select');
710710

711-
/** @var array{models: list<string>} $session */
712711
$session = $sessionStorage->get($definition->getName() . '.' . $selectAction);
712+
if (!is_array($session) || !isset($session['models'])) {
713+
return null;
714+
}
715+
/** @var array{models: list<string>} $session */
713716

714717
$originalPropertyName = null;
715718
foreach ($session['models'] as $modelId) {
716-
if (null !== $originalPropertyName) {
717-
break;
718-
}
719-
720-
$propertyNamePrefix = \str_replace('::', '____', $modelId) . '_';
721-
if (0 !== strpos($propertyName, $propertyNamePrefix)) {
719+
$propertyNamePrefix = \str_replace('::', '____', ((string) $modelId)) . '_';
720+
if (!str_starts_with($propertyName, $propertyNamePrefix)) {
722721
continue;
723722
}
724723

725724
$originalPropertyName = \substr($propertyName, \strlen($propertyNamePrefix));
725+
break;
726726
}
727727

728728
if (null === $originalPropertyName) {

src/Contao/View/Contao2BackendView/Subscriber/MultipleHandlerSubscriber.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of contao-community-alliance/dc-general.
55
*
6-
* (c) 2013-2024 Contao Community Alliance.
6+
* (c) 2013-2025 Contao Community Alliance.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -13,7 +13,7 @@
1313
* @package contao-community-alliance/dc-general
1414
* @author Sven Baumann <baumann.sv@gmail.com>
1515
* @author Ingolf Steinhardt <info@e-spin.de>
16-
* @copyright 2013-2024 Contao Community Alliance.
16+
* @copyright 2013-2025 Contao Community Alliance.
1717
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0
1818
* @filesource
1919
*/
@@ -318,14 +318,22 @@ private function findModelIdByPropertyName(BuildWidgetEvent $event)
318318
$sessionStorage = $environment->getSessionStorage();
319319
assert($sessionStorage instanceof SessionStorageInterface);
320320

321-
/** @var array{models: list<string>} $session */
322321
$session = $sessionStorage->get($dataDefinition->getName() . '.' . $inputProvider->getParameter('mode'));
322+
if (!is_array($session) || !isset($session['models'])) {
323+
return;
324+
}
325+
/** @var array{models: list<string>} $session */
323326

324327
$model = null;
325328
foreach ($session['models'] as $sessionModel) {
326329
$model = $sessionModel;
327330

328-
if (!str_starts_with($event->getProperty()->getName(), \str_replace('::', '____', $sessionModel))) {
331+
if (
332+
!str_starts_with(
333+
$event->getProperty()->getName(),
334+
\str_replace('::', '____', ((string) $sessionModel))
335+
)
336+
) {
329337
continue;
330338
}
331339

src/Contao/View/Contao2BackendView/Widget/FileTreeOrder.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of contao-community-alliance/dc-general.
55
*
6-
* (c) 2013-2023 Contao Community Alliance.
6+
* (c) 2013-2025 Contao Community Alliance.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -16,13 +16,15 @@
1616
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
1717
* @author Stefan Heimes <stefan_heimes@hotmail.com>
1818
* @author Ingolf Steinhardt <info@e-spin.de>
19-
* @copyright 2013-2023 Contao Community Alliance.
19+
* @copyright 2013-2025 Contao Community Alliance.
2020
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
2121
* @filesource
2222
*/
2323

2424
namespace ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Widget;
2525

26+
use Contao\Validator;
27+
2628
/**
2729
* This widget is a supporting widget to store the file tree orderings.
2830
*
@@ -68,7 +70,13 @@ protected function getSerializedValue()
6870
if (null === $this->varValue) {
6971
$this->varValue = [];
7072
}
73+
$files = [];
74+
foreach ($this->varValue as $binUuid) {
75+
if (Validator::isBinaryUuid($binUuid)) {
76+
$files[] = $binUuid;
77+
}
78+
}
7179

72-
return \implode(',', \array_map('\Contao\StringUtil::binToUuid', $this->varValue));
80+
return \implode(',', \array_map('\Contao\StringUtil::binToUuid', $files));
7381
}
7482
}

src/Controller/Ajax3X.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ protected function reloadTree()
321321
$value = $input->hasValue('value') ? $input->getValue('value', true) : '';
322322

323323
$fieldName = $this->getFieldName();
324-
assert(is_string($fieldName));
324+
if (null === $fieldName) {
325+
throw new ResponseException(new Response('No update of the widget, as no field name was found.'));
326+
}
325327

326328
$widget = $this->getWidget($fieldName, $serializedId, $value);
327329
assert($widget instanceof Widget);
@@ -381,6 +383,9 @@ protected function setLegendState()
381383
* Get the field name.
382384
*
383385
* @return null|string
386+
*
387+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
388+
* @SuppressWarnings(PHPMD.NPathComplexity)
384389
*/
385390
private function getFieldName()
386391
{
@@ -392,7 +397,7 @@ private function getFieldName()
392397

393398
$fieldName = $inputProvider->hasValue('name') ? $inputProvider->getValue('name') : null;
394399
if (null === $fieldName) {
395-
return $fieldName;
400+
return null;
396401
}
397402

398403
if (('select' !== $inputProvider->getParameter('act')) && ('edit' !== $inputProvider->getParameter('mode'))) {
@@ -405,16 +410,19 @@ private function getFieldName()
405410
$sessionStorage = $environment->getSessionStorage();
406411
assert($sessionStorage instanceof SessionStorageInterface);
407412

408-
/** @var array{models: list<string>} $session */
409413
$session = $sessionStorage->get($dataDefinition->getName() . '.' . $inputProvider->getParameter('select'));
414+
if (!is_array($session) || !isset($session['models'])) {
415+
return null;
416+
}
417+
/** @var array{models: list<string>} $session */
410418

411419
$originalPropertyName = null;
412420
foreach ($session['models'] as $modelId) {
413421
if (null !== $originalPropertyName) {
414422
break;
415423
}
416424

417-
$propertyNamePrefix = str_replace('::', '____', $modelId) . '_';
425+
$propertyNamePrefix = str_replace('::', '____', ((string) $modelId)) . '_';
418426
if (!str_starts_with($fieldName, $propertyNamePrefix)) {
419427
continue;
420428
}

0 commit comments

Comments
 (0)