Skip to main content
Mark Llobrera

Top level navigation menu

Link Widget in Drupal 7 Custom Forms

Via Will Vedder: if you want to embed a link widget (with Title and URL fields) in a form, you can do something like this (in your code that uses the Form API to build the form):

$form['my_link']() = array(
    '#type' => 'link_field',
    '#title' => t('CTA Link'),
    '#description' => t('Optional Call to Action link.'),
    '#field_name' => 'link_field',
    '#field_parents' => array(),
    '#language' => 'und',
    '#delta' => 0,
);

That is different from simply rendering a link in the form:

$form['my_link']() = array(
    '#type' => 'link',
    '#title' => t('Example link'),
    '#href' => 'http://foo.com',
);