link_key; $row[] = $link->title; $row[] = l(t('edit'), 'admin/build/custom_links/' . $link->lid . '/edit') . ' ' . l(t('delete'), 'admin/build/custom_links/' . $link->lid . '/delete'); $rows[] = $row; } if (count($rows) == 0) { $rows[] = array(array('data' => t('No custom links have been defined.'), 'colspan' => 3)); } $rows[] = array(array('data' => l(t('Add a new custom link'), 'admin/build/custom_links/add'), 'colspan' => 3)); return theme('table', $header, $rows); } // Displays an edit form for a custom link record. function custom_links_form(&$form_state, $link = NULL) { global $base_url; $lid = empty($link->lid) ? NULL : $link->lid; $form['lid'] = array( '#type' => 'value', '#value' => $lid, ); $form['link'] = array( '#type' => 'fieldset', '#title' => t('Link details'), ); $form['link']['link_key'] = array( '#type' => 'textfield', '#title' => t('Link key'), '#description' => t('A unique string to identify this link. It will also be used as a CSS class when the link is output as HTML.'), '#default_value' => $lid ? $link->link_key : NULL ); $form['link']['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#description' => t("The visible text of the link seen by the user."), '#default_value' => $lid ? $link->title : NULL ); $form['link']['check_html'] = array( '#type' => 'checkbox', '#title' => t('Title uses HTML'), '#return_value' => 1, '#default_value' => $lid ? $link->check_html : 0 ); $form['link']['path'] = array( '#type' => 'textfield', '#title' => t('Path'), '#description' => t("The Drupal path for the link. (!sample_url)", array('!sample_url' => $base_url .'/node/1#comment')), '#default_value' => $lid ? $link->path : NULL ); $form['link']['querystring'] = array( '#type' => 'textfield', '#title' => t('Querystring'), '#description' => t("The optional querystring for the link. (!sample_url)", array('!sample_url' => $base_url .'/article?id=1')), '#default_value' => $lid ? $link->query : NULL ); $form['link']['fragment'] = array( '#type' => 'textfield', '#title' => t('Anchor'), '#description' => t("The optional HTML anchor for the link. (!sample_url)", array('!sample_url' => $base_url .'/node/1#comment')), '#default_value' => $lid ? $link->fragment : NULL ); $form['help'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Placeholder tokens'), '#description' => t("The following placeholder tokens can be used in paths, titles, querystrings, and anchors. they will be replaced with the appropriate values."), ); if (module_exists('token')) { $form['help']['tokens'] = array( '#value' => theme('token_help', 'node'), ); } else { $form['help']['#description'] = t("To use dynamic placeholder tokens in your paths and titles (the ID or title of the current node, for example), download and install the Token module from Drupal.org.", array('@token' => 'http://www.drupal.org/project/token')); $form['help']['#collapsible'] = FALSE; $form['help']['#collapsed'] = FALSE; } $form['filters'] = array( '#type' => 'fieldset', '#title' => t('Link conditions'), ); $modes = array( 0 => t('In full node views'), 1 => t('In teaser node views'), 2 => t('In both teaser and full node views'), 3 => t('In a sidebar block'), ); $form['filters']['display'] = array( '#type' => 'select', '#title' => t('Display'), '#options' => $modes, '#default_value' => $lid ? $link->display : 2, ); $options['*all*'] = t('All node types'); foreach (node_get_types('names') as $type => $name) { $options[$type] = $name; } $form['filters']['node_type'] = array( '#type' => 'select', '#title' => t('Node type'), '#options' => $options, '#description' => t('If selected, the link will only be added to nodes of this type.'), '#default_value' => $lid ? $link->node_type : NULL, ); $options = array('' => t('No permission required')); foreach (module_list(FALSE, FALSE, TRUE) as $module) { if ($permissions = module_invoke($module, 'perm')) { asort($permissions); foreach ($permissions as $perm) { $options[$module][$perm] = $perm; } } } $form['filters']['author_perm'] = array( '#type' => 'select', '#title' => t('Author permission restriction'), '#options' => $options, '#description' => t('A specific permission that the author of the node must have for the link to be added.'), '#default_value' => $lid ? $link->author_perm : NULL ); $form['filters']['viewer_perm'] = array( '#type' => 'select', '#title' => t('Viewer permission restriction'), '#options' => $options, '#description' => t('A specific permission that the viewer of the node must have for the link to be added.'), '#default_value' => $lid ? $link->viewer_perm : 'access content' ); $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); if ($lid) { $form['buttons']['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), '#submit' => array('custom_links_form_delete_submit'), ); } return $form; } function custom_links_form_validate($form, &$form_state) { if (strpos($form_state['values']['link_key'], array(' ', '#', '.', '%', '^')) !== FALSE) { form_set_error('link][link_key', t('The link key may not contain spaces or punctuation.')); } } function custom_links_form_submit($form, &$form_state) { $link = (object)$form_state['values']; if ($link->node_type == '*all*') { $link->node_type = ''; } $link->query = $link->querystring; _custom_links_save_link($link); $form_state['redirect'] = 'admin/build/custom_links'; } /** * Button sumit function: handle the 'Delete' button on the node form. */ function custom_links_form_delete_submit($form, &$form_state) { $destination = ''; if (isset($_REQUEST['destination'])) { $destination = drupal_get_destination(); unset($_REQUEST['destination']); } $form_state['redirect'] = array('admin/build/custom_links/'. $form_state['values']['lid'] .'/delete', $destination); } /** * Menu callback -- ask for confirmation of link deletion */ function custom_links_delete_form(&$form_state, $link) { $form['lid'] = array( '#type' => 'value', '#value' => $link->lid, ); return confirm_form($form, t('Are you sure you want to delete %title?', array('%title' => $link->title)), isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/custom_links/', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } /** * Execute custom link deletion. */ function custom_links_delete_form_submit($form, &$form_state) { if ($form_state['values']['confirm']) { _custom_links_delete_link($form_state['values']['lid']); } $form_state['redirect'] = 'admin/build/custom_links'; }