You are here

function _shortcut_link_form_elements in Drupal 7

Helper function for building a form for adding or editing shortcut links.

Parameters

$shortcut_link: (optional) An array representing the shortcut link that will be edited. If not provided, a new link will be created.

Return value

An array of form elements.

2 calls to _shortcut_link_form_elements()
shortcut_link_add in modules/shortcut/shortcut.admin.inc
Form callback: builds the form for adding a new shortcut link.
shortcut_link_edit in modules/shortcut/shortcut.admin.inc
Form callback: builds the form for editing a shortcut link.

File

modules/shortcut/shortcut.admin.inc, line 466
Administrative page callbacks for the shortcut module.

Code

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_get_path_alias($shortcut_link['link_path']);
  }
  $form['shortcut_link']['#tree'] = TRUE;
  $form['shortcut_link']['link_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('The name of the shortcut.'),
    '#size' => 40,
    '#maxlength' => 255,
    '#default_value' => $shortcut_link['link_title'],
    '#required' => TRUE,
  );
  $form['shortcut_link']['link_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#description' => t('The path to the shortcut.'),
    '#size' => 40,
    '#maxlength' => 255,
    '#field_prefix' => url(NULL, array(
      'absolute' => TRUE,
    )) . (variable_get('clean_url', 0) ? '' : '?q='),
    '#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;
}