Loading
feat: #3630849: Add a Webform element for T.C. Kimlik No
Closes #3630849
Problem
The module provides a tckk Form API element and the tckk_field.validator service, but no WebformElement plugin. Using '#type': tckk in a webform falls back to Webform's generic element plugin. The element is then missing from the form builder, its properties cannot be edited there, and #states, submission display and export are not guaranteed.
Changes
New submodule tckk_field_webform
- Depends on
tckk_fieldandwebform:webform. The main module keeps working without Webform. WebformElementplugintckk(TCKimlikNo, extendsTextBase) wraps the existingtckkelement. Validation stays intckk_field.validator.- Defaults:
#maxlength11 andinputmode="numeric". - New
#tckk_errorproperty: an optional, translatable message for invalid numbers. It can be edited in the form builder under "Validation". - Provides valid sample numbers for Webform's "Test" form.
Changes to the tckk element (TckkFieldElement)
These were needed for the Webform element to behave correctly:
preRenderprinted onlyid,nameandvalue, so#maxlengthnever reached the HTML. It now also printssize,maxlengthandplaceholder, the same as core's textfield.- Added a value callback like core's textfield. Before, non-scalar input (for example a tampered
tckk[]=xrequest) reachedTckkValidator::validate(string)and caused a TypeError (HTTP 500). - Supports
#tckk_error. Only the first error per element is kept, so the element itself has to set the custom message.
Other
- Functional test
TckkWebformElementTest, which checks that:- the plugin is used instead of the generic element;
maxlengthandinputmodeare rendered;- the element is listed and editable in the form builder;
- valid, invalid and too-long values are handled;
#statesvisible/required works: a hidden element is not validated or stored, and a required one shows the custom message.
drupal/webform: ^6.2added torequire-dev, and asuggestentry added.- New
README.md, since the project had none.
Testing
The project has no GitLab CI configuration, so tests were run locally on Drupal 11.4.9, PHP 8.4, PostgreSQL 18 and Webform 6.3.1:
vendor/bin/phpunit -c web/core web/modules/contrib/tckk_fieldResult: 15 tests, 37 assertions, all passing. The remaining deprecation notices come from core and Webform. PHPCS (Drupal, DrupalPractice) reports no issues in new or changed files.
Notes
tckk_field_webform.info.ymldeclares^9 || ^10 || ^11. It was only tested on Drupal 11 with Webform 6.3. Drupal 9 and 10 with Webform 6.2 were not tested.- Submission display, export and Views integration come from
TextBaseand were not tested separately. - The branch is based on
1.0.x, which already includes the validator fix from #3630848.