Helper function for building a form for adding or editing shortcut links.
$shortcut_link: (optional) An array representing the shortcut link that will be edited. If not provided, a new link will be created.
An array of form elements.
function _shortcut_link_form_elements($shortcut_link = NULL) {
if (!isset($shortcut_link)) {
$shortcut_link = array(
'link_title' => '',
'link_path' => '',
);
}
else {
$shortcut_link['link_path'] = $shortcut_link['link_path'] == '<front>' ? '' : drupal_container()
->get('path.alias_manager')
->getPathAlias($shortcut_link['link_path']);
}
$form['shortcut_link']['#tree'] = TRUE;
$form['shortcut_link']['link_title'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => $shortcut_link['link_title'],
'#required' => TRUE,
);
$form['shortcut_link']['link_path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#size' => 40,
'#maxlength' => 255,
'#field_prefix' => url(NULL, array(
'absolute' => TRUE,
)),
'#default_value' => $shortcut_link['link_path'],
);
$form['#validate'][] = 'shortcut_link_edit_validate';
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}