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' => 'link', '#title' => $this->t('Link title'), '#url' => 'Hmm?', '#options' => ['external' => TRUE] ]; return $form; }