1

In order to modify the length of a file field description field I put the following line in settings.php:

$config['file.settings']['description']['length'] = 512;

Now I want to do the same for the link field. How can I change the max length of the link text (without patching the module)?

I think the problem is that FileWidget.php gets the length from the configuration

'#maxlength' => $config->get('description.length')

whereas it is hardcoded in LinkWidget.php:

'#maxlength' => 255

2

If you go for module then you can check Maxlength module.

Maxlength allows you to set maximum length of any field on any form making use of the form API. This includes fields created using the UI. (Example: any text field on a node)

  • I know this module, but I was hoping it is possible by adding just another line. – 0711master Feb 4 '17 at 11:37
  • So, I tried the module, but there is no option for the max length of the link text field. – 0711master Feb 7 '17 at 10:38
  • Seems this is a known issue: drupal.org/project/link/issues/1307788 Currently have MaxLength module installed. Can confirm that you still cannot set the character count limit of a link field in drupal 8. – Nick Dubois Aug 14 '18 at 18:59
-1
function your_module_field_widget_form_alter(&$element, FormStateInterface 
$form_state, $context) {
if($element['uri']['#title']=='URL' && $element['title']['#title']=='Link 
 text'){
$element['title']['#maxlength']=20;
 }

}

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.