Skip to content

Commit

Permalink
[BUGFIX] Bring back valuePicker for TCA type email
Browse files Browse the repository at this point in the history
While extracting dedicated TCA types from the god type `input`, the
`valuePicker` option was forgotten for type `email`. Other types like
`number` do have this option.

An acceptance test is added to ensure this option will not be dropped
by accident in the future.

Resolves: #103510
Related: #97013
Releases: main, 12.4
Change-Id: I95c51d858ca9cb3caefa174cd8ce5946c8352aa2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83639
Tested-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
nhovratov committed Apr 2, 2024
1 parent 6ab0c9b commit e7b6c80
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
29 changes: 28 additions & 1 deletion typo3/sysext/backend/Classes/Form/Element/EmailElement.php
Expand Up @@ -17,6 +17,7 @@

namespace TYPO3\CMS\Backend\Form\Element;

use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
Expand Down Expand Up @@ -141,6 +142,31 @@ public function render(): array
$attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
}

$valuePickerHtml = [];
if (is_array($config['valuePicker']['items'] ?? false)) {
$valuePickerConfiguration = [
'mode' => $config['valuePicker']['mode'] ?? 'replace',
'linked-field' => '[data-formengine-input-name="' . $itemName . '"]',
];
$valuePickerAttributes = array_merge(
[
'class' => 'form-select form-control-adapt',
],
$this->getOnFieldChangeAttrs('change', $parameterArray['fieldChangeFunc'] ?? [])
);

$valuePickerHtml[] = '<typo3-formengine-valuepicker ' . GeneralUtility::implodeAttributes($valuePickerConfiguration, true) . '>';
$valuePickerHtml[] = '<select ' . GeneralUtility::implodeAttributes($valuePickerAttributes, true) . '>';
$valuePickerHtml[] = '<option></option>';
foreach ($config['valuePicker']['items'] as $item) {
$valuePickerHtml[] = '<option value="' . htmlspecialchars((string)$item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
}
$valuePickerHtml[] = '</select>';
$valuePickerHtml[] = '</typo3-formengine-valuepicker>';

$resultArray['javaScriptModules'][] = JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-wizard/value-picker.js');
}

$fieldControlResult = $this->renderFieldControl();
$fieldControlHtml = $fieldControlResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
Expand All @@ -156,9 +182,10 @@ public function render(): array
$mainFieldHtml[] = '<input type="email" ' . GeneralUtility::implodeAttributes($attributes, true) . ' />';
$mainFieldHtml[] = '<input type="hidden" name="' . $itemName . '" value="' . htmlspecialchars((string)$itemValue) . '" />';
$mainFieldHtml[] = '</div>';
if (!empty($fieldControlHtml)) {
if (!empty($valuePickerHtml) || !empty($fieldControlHtml)) {
$mainFieldHtml[] = '<div class="form-wizards-items-aside form-wizards-items-aside--field-control">';
$mainFieldHtml[] = '<div class="btn-group">';
$mainFieldHtml[] = implode(LF, $valuePickerHtml);
$mainFieldHtml[] = $fieldControlHtml;
$mainFieldHtml[] = '</div>';
$mainFieldHtml[] = '</div>';
Expand Down
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine;

use Codeception\Attribute\DataProvider;
use Codeception\Example;
use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester;
use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;

/**
* Tests for "elements_basic" simple input fields of ext:styleguide
*/
final class ElementsBasicEmailCest extends AbstractElementsBasicCest
{
/**
* Open list module of styleguide elements basic page
*/
public function _before(ApplicationTester $I, PageTree $pageTree): void
{
$I->useExistingSession('admin');
$I->click('List');
$pageTree->openPath(['styleguide TCA demo', 'elements basic']);
// Wait until DOM actually rendered everything
$I->switchToContentFrame();

// Open record and wait until form is ready
$I->waitForText('elements basic', 20);
$editRecordLinkCssPath = '#recordlist-tx_styleguide_elements_basic a[aria-label="Edit record"]';
$I->click($editRecordLinkCssPath);
$I->waitForElementNotVisible('#t3js-ui-block');
$I->waitForText('Edit Form', 3, 'h1');

// Make sure the test operates on the "email" tab
$I->click('input');
}

/**
* Data provider to check various type=email variants
*/
private function emailFieldsDataProvider(): array
{
return [
[
'label' => 'input_39',
'inputValue' => 'foo@example.com',
'expectedValue' => 'foo@example.com',
'expectedInternalValue' => 'foo@example.com',
'expectedValueAfterSave' => 'foo@example.com',
'comment' => '',
],
];
}

#[DataProvider('emailFieldsDataProvider')]
public function emailFields(ApplicationTester $I, Example $testData): void
{
$this->runInputFieldTest($I, $testData);
}
}

0 comments on commit e7b6c80

Please sign in to comment.