|
28 | 28 |
|
29 | 29 | namespace MetaModels\FrontendIntegration; |
30 | 30 |
|
| 31 | +use Contao\StringUtil; |
31 | 32 | use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents; |
32 | 33 | use ContaoCommunityAlliance\Contao\Bindings\Events\Controller\RedirectEvent; |
33 | 34 | use Contao\CoreBundle\Csrf\ContaoCsrfTokenManager; |
@@ -427,8 +428,13 @@ protected function getFilters() |
427 | 428 | } |
428 | 429 | } |
429 | 430 |
|
| 431 | + // TODO: hier presets einbauen... |
| 432 | + $values = \array_merge($all->getSlugParameters(), $all->getGetParameters()); |
| 433 | + $baseParameters = $this->getBaseParameters($values); |
| 434 | + //$baseParameters = ['select' => 'abteilung-a']; |
430 | 435 | $arrWidgets = $filterSetting->getParameterFilterWidgets( |
431 | | - \array_merge($all->getSlugParameters(), $all->getGetParameters()), |
| 436 | + \array_merge($baseParameters, $values), |
| 437 | + //\array_merge($all->getSlugParameters(), $all->getGetParameters()), |
432 | 438 | $jumpToInformation, |
433 | 439 | $filterOptions |
434 | 440 | ); |
@@ -622,4 +628,46 @@ public function generateClearAll($strContent, $strTemplate) |
622 | 628 |
|
623 | 629 | return $strContent; |
624 | 630 | } |
| 631 | + |
| 632 | + private function getBaseParameters($values): array |
| 633 | + { |
| 634 | + if ([] === ($presets = StringUtil::deserialize($this->objFilterConfig->metamodel_filterparams, true))) { |
| 635 | + return []; |
| 636 | + } |
| 637 | + |
| 638 | + if (null === ($filterSetting = $this->objFilterConfig->getFilterCollection())) { |
| 639 | + throw new RuntimeException( |
| 640 | + 'Error: no filter object defined, call setFilterSettings() before setFilterParameters().' |
| 641 | + ); |
| 642 | + } |
| 643 | + |
| 644 | + $presetNames = $filterSetting->getParameters(); |
| 645 | + $filterParamKeys = \array_keys($filterSetting->getParameterFilterNames()); |
| 646 | + |
| 647 | + $processed = []; |
| 648 | + |
| 649 | + // We have to use all the preset values we want first. |
| 650 | + foreach ($presets as $presetName => $presetValues) { |
| 651 | + if (\in_array($presetName, $presetNames, true)) { |
| 652 | + $processed[$presetName] = $presetValues['value']; |
| 653 | + } |
| 654 | + } |
| 655 | + |
| 656 | + // Now we have to use all FE filter params, that are either: |
| 657 | + // * not contained within the presets |
| 658 | + // * or are overridable. |
| 659 | + foreach ($filterParamKeys as $filterParameterKey) { |
| 660 | + // Unknown parameter? - next please. |
| 661 | + if (!\array_key_exists($filterParameterKey, $values)) { |
| 662 | + continue; |
| 663 | + } |
| 664 | + |
| 665 | + // Not a preset or allowed to override? - use value. |
| 666 | + if ((!\array_key_exists($filterParameterKey, $presets)) || (bool) $presets[$filterParameterKey]['use_get']) { |
| 667 | + $processed[$filterParameterKey] = $values[$filterParameterKey]; |
| 668 | + } |
| 669 | + } |
| 670 | + |
| 671 | + return $processed; |
| 672 | + } |
625 | 673 | } |
0 commit comments