Skip to content

Commit 107949e

Browse files
committed
[BUGFIX] Properly parse Country property in CountrySelectViewHelper
The implementation of #99911 missed to address that the `<f:form.countrySelect>` ViewHelper needs to properly evaluate the Country object, when referenced as a domain model property instead of getting accessed via `value`. This patch adds a test for this case and adapts retrieval in the ViewHelper's `convertToPlainValue()` method. Also, a drive-by typo is fixed. Resolves: #107200 Related: #99911 Related: #104997 Releases: main Change-Id: Ibf202c21a70d96303b188d7a5ad4fd45e055f263 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/90238 Tested-by: Garvin Hicking <garvin@hick.ing> Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Simon Praetorius <simon@praetorius.me> Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Tested-by: Simon Praetorius <simon@praetorius.me> Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Garvin Hicking <garvin@hick.ing>
1 parent ccee9fb commit 107949e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

typo3/sysext/extbase/Tests/Functional/Persistence/Generic/Mapper/TcaTypeCountryTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
use TYPO3\CMS\Core\Country\CountryProvider;
2525
use TYPO3\CMS\Core\Http\ServerRequest;
2626
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
27+
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
28+
use TYPO3\CMS\Extbase\Mvc\Request;
2729
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
30+
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
2831
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
32+
use TYPO3Fluid\Fluid\View\TemplateView;
2933
use TYPO3Tests\BlogExample\Domain\Model\Person;
3034
use TYPO3Tests\BlogExample\Domain\Repository\PersonRepository;
3135

@@ -44,6 +48,28 @@ protected function setUp(): void
4448
$this->get(ConfigurationManagerInterface::class)->setRequest($request);
4549
}
4650

51+
#[Test]
52+
public function tcaTypeCountryCanBeMappedForFormUsage(): void
53+
{
54+
$countryProvider = $this->get(CountryProvider::class);
55+
$person = new Person();
56+
$person->setCountry($countryProvider->getByAlpha2IsoCode('DE'));
57+
58+
$serverRequest = (new ServerRequest())
59+
->withAttribute('extbase', new ExtbaseRequestParameters())
60+
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
61+
$context = $this->get(RenderingContextFactory::class)->create([], new Request($serverRequest));
62+
$context->getTemplatePaths()->setTemplateSource('
63+
<f:form object="{person}" objectName="person">
64+
<f:form.countrySelect name="country" property="country" onlyCountries="{0: \'CH\', 1: \'AT\', 2: \'DE\'}" />
65+
</f:form>
66+
');
67+
$templateView = (new TemplateView($context));
68+
$templateView->assign('person', $person);
69+
$result = $templateView->render();
70+
self::assertStringContainsString('<option value="DE" selected="selected">', $result);
71+
}
72+
4773
#[Test]
4874
public function tcaTypeCountryCanBeHandled(): void
4975
{

typo3/sysext/fluid/Classes/ViewHelpers/Form/AbstractFormFieldViewHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected function getPropertyValue()
318318

319319
/**
320320
* Internal method which checks if we should evaluate a domain object or just output arguments['name']
321-
* and arguments['value']. Returns true if domoin object should be evaluated.
321+
* and arguments['value']. Returns true if domain object should be evaluated.
322322
*/
323323
protected function isObjectAccessorMode(): bool
324324
{

typo3/sysext/fluid/Classes/ViewHelpers/Form/CountrySelectViewHelper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,20 @@ protected function getCountryList(): array
192192
->setExcludeCountries($this->arguments['excludeCountries'] ?? []);
193193
return GeneralUtility::makeInstance(CountryProvider::class)->getFiltered($filter);
194194
}
195+
196+
/**
197+
* Converts an arbitrary value to a plain value.
198+
* Evaluates possible direct "Country" type properties.
199+
*
200+
* @param mixed $value The value to convert
201+
* @return mixed
202+
*/
203+
protected function convertToPlainValue($value)
204+
{
205+
if ($value instanceof Country) {
206+
return $value->getAlpha2IsoCode();
207+
}
208+
return parent::convertToPlainValue($value);
209+
}
210+
195211
}

0 commit comments

Comments
 (0)