Add link field in custom form I want add link field (label + url internal/external) in custom form

This not work:

$form['test_ink'] = array(
  '#type' =&gt; 'link',
  '#title' =&gt; $this-&gt;t('Link title'),
  '#url' =&gt; '',
);
The link (Link) render element type is used to render an anchor element on a page, and not used to provide an input element in a form that is constrained for URLs.

As an example you may look at LinkWidget::formElement, which shows how that field widget creates form elements for a Link field. And the way it does this is to use the url (Url) form element, which will provide an input element that validates URLs. Make sure that the #url property is a valid (Url) object.

$form['test_ink'] = [
  '#type' =&gt; 'url',
  '#title' =&gt; $this-&gt;t('Link title'),
  // Example of a Url object from a route. See the documentation
  // for more methods that may help generate a Url object.
  '#url' =&gt; Url::fromRoute('entity.node.canonical', ['node' =&gt; 1]),
];


Edit:


Added @imclean's suggestion to the answer for readability