I have some fields which are configured as long text fields, which I need to display as <input type="text /> instead of <textarea></textarea>.

I'm trying to find the correct naming convention so that I can have some theme overrides in my templates folder.

Is that the correct approach? Is there documentation about overriding specific field outputs on edit screens?

  • 1
    You can't "theme" a Form API input field the same way as frontend output fields. You have to create your own module and implement a custom field widget. – Hudri Jul 15 at 20:27

Drupal textfield widget can only be applied to string fields. https://git.drupalcode.org/project/drupal/blob/8.7.4/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php#L9

However it's not a big deal to alter its definition and make it support long strings.

 * Implements hook_field_widget_info_alter().
function HOOK_field_widget_info_alter(array &$info) {
  $info['string_textfield']['field_types'][] = 'string_long';

After having this done it should be possible to assign textfield widget to long text fields on "Manage form display" page.

  • Nice. That did it! Thank you. – jhchnc Jul 22 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.