Add a link field to block form I've created a module with a custom block that extends BlockBase. To the block form I added multiple textfields and select boxes, by simply specifying the formatter in the '#type' configuration. 

My next step is to add a button that links to internal/external content and I've tried adding different types, such as 'link' but without any luck.

I found LinkFormatter, but I can't figure out how to use it properly with block forms.

What has to be added to the blockForm method in order to create a link field (just like the link field that's selectable within a custom block type):



My current code:

public function blockForm($form, FormStateInterface $form_state) {
  //...
  $form['link'] = [
    '#type' =&gt; 'link',
    '#title' =&gt; $this-&gt;t('Link title'),
    '#url' =&gt; 'Hmm?',
    '#options' =&gt; ['external' =&gt; TRUE]
  ];

  return $form;
}
You want to change '#type' =&gt; 'link' to '#type' =&gt; 'url'

public function blockForm($form, FormStateInterface $form_state) {
  //...
  $form['link'] = [
    '#type' =&gt; 'url',
    '#title' =&gt; $this-&gt;t('Link title'),
    '#options' =&gt; ['external' =&gt; TRUE]
  ];

  return $form;
}