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_field and webform:webform. The main module keeps working without Webform.
  • WebformElement plugin tckk (TCKimlikNo, extends TextBase) wraps the existing tckk element. Validation stays in tckk_field.validator.
  • Defaults: #maxlength 11 and inputmode="numeric".
  • New #tckk_error property: 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:

  • preRender printed only id, name and value, so #maxlength never reached the HTML. It now also prints size, maxlength and placeholder, the same as core's textfield.
  • Added a value callback like core's textfield. Before, non-scalar input (for example a tampered tckk[]=x request) reached TckkValidator::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;
    • maxlength and inputmode are rendered;
    • the element is listed and editable in the form builder;
    • valid, invalid and too-long values are handled;
    • #states visible/required works: a hidden element is not validated or stored, and a required one shows the custom message.
  • drupal/webform: ^6.2 added to require-dev, and a suggest entry 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_field

Result: 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.yml declares ^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 TextBase and were not tested separately.
  • The branch is based on 1.0.x, which already includes the validator fix from #3630848.

Merge request reports

Loading
Loading