| 1 |
<?php |
<?php |
| 2 |
// $Id: custom_breadcrumbs.admin.inc,v 1.1 2008/01/27 08:30:15 eaton Exp $ |
// $Id: custom_breadcrumbs.admin.inc,v 1.1.2.5 2009/09/30 12:12:11 mgn Exp $ |
| 3 |
|
|
| 4 |
// Lists all current custom breadcrumbs, and provides a link to the edit page. |
/** |
| 5 |
|
* @file |
| 6 |
|
* Admin page callback file for the custom_breadcrumbs module. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
/** |
| 10 |
|
* Lists all current custom breadcrumbs, and provides a link to the edit page. |
| 11 |
|
*/ |
| 12 |
function custom_breadcrumbs_page() { |
function custom_breadcrumbs_page() { |
| 13 |
$breadcrumbs = _custom_breadcrumbs_load_all_breadcrumbs(TRUE); |
$breadcrumbs = _custom_breadcrumbs_load_all_breadcrumbs(TRUE); |
| 14 |
|
|
| 27 |
|
|
| 28 |
$rows[] = array(array('data' => l(t('Add a new custom breadcrumb'), 'admin/build/custom_breadcrumbs/add'), 'colspan' => 2)); |
$rows[] = array(array('data' => l(t('Add a new custom breadcrumb'), 'admin/build/custom_breadcrumbs/add'), 'colspan' => 2)); |
| 29 |
|
|
| 30 |
return theme('table', $header, $rows); |
$build = array(); |
| 31 |
} |
$build['breadcrumb_table'] = array('#markup' => theme('table', $header, $rows)); |
| 32 |
|
|
| 33 |
|
return $build; |
| 34 |
|
} |
| 35 |
|
|
| 36 |
// Displays an edit form for a custom breadcrumb record. |
/** |
| 37 |
|
* Display an edit form for a custom breadcrumb record. |
| 38 |
|
*/ |
| 39 |
function custom_breadcrumbs_form() { |
function custom_breadcrumbs_form() { |
| 40 |
$bid = arg(4); |
$bid = arg(4); |
| 41 |
if (isset($bid)) { |
if (isset($bid)) { |
| 47 |
} |
} |
| 48 |
|
|
| 49 |
$options = array(); |
$options = array(); |
| 50 |
foreach (node_get_types('names') as $type => $name) { |
$types = node_type_get_names(); |
| 51 |
|
foreach ($types as $type => $name) { |
| 52 |
$options[$type] = $name; |
$options[$type] = $name; |
| 53 |
} |
} |
| 54 |
|
|
| 58 |
'#required' => TRUE, |
'#required' => TRUE, |
| 59 |
'#options' => $options, |
'#options' => $options, |
| 60 |
'#description' => t('The node type this custom breadcrumb trail will apply to.'), |
'#description' => t('The node type this custom breadcrumb trail will apply to.'), |
| 61 |
'#default_value' => $bid ? $breadcrumb->node_type : NULL, |
'#default_value' => isset($breadcrumb->node_type) ? $breadcrumb->node_type : NULL, |
| 62 |
); |
); |
| 63 |
|
|
| 64 |
$form['visibility_php'] = array( |
$form['visibility_php'] = array( |
| 65 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 66 |
'#title' => t('Breadcrumb visibility'), |
'#title' => t('Breadcrumb visibility'), |
| 67 |
'#access' => user_access('use php in custom pagers'), |
'#access' => user_access('use php in custom breadcrumbs'), |
| 68 |
'#description' => t('Determine whether this breadcrumb should be displayed by using a snippet of PHP to return TRUE or FALSE. Note that this code has access to the $node variable, and can check its type or any other property.'), |
'#description' => t('Determine whether this breadcrumb should be displayed by using a snippet of PHP to return TRUE or FALSE. Note that this code has access to the $node variable, and can check its type or any other property.'), |
| 69 |
'#default_value' => $bid ? $breadcrumb->visibility_php : '', |
'#default_value' => isset($breadcrumb->visibility_php) ? $breadcrumb->visibility_php : '', |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
$form['titles'] = array( |
$form['titles'] = array( |
| 74 |
'#title' => t('Titles'), |
'#title' => t('Titles'), |
| 75 |
'#required' => TRUE, |
'#required' => TRUE, |
| 76 |
'#description' => t('A list of titles for the breadcrumb links, one on each line.'), |
'#description' => t('A list of titles for the breadcrumb links, one on each line.'), |
| 77 |
'#default_value' => $bid ? $breadcrumb->titles : NULL |
'#default_value' => isset($breadcrumb->titles) ? $breadcrumb->titles : NULL, |
| 78 |
); |
); |
| 79 |
|
|
| 80 |
$form['paths'] = array( |
$form['paths'] = array( |
| 82 |
'#title' => t('Paths'), |
'#title' => t('Paths'), |
| 83 |
'#required' => TRUE, |
'#required' => TRUE, |
| 84 |
'#description' => t('A list of Drupal paths for the breadcrumb links, one on each line.'), |
'#description' => t('A list of Drupal paths for the breadcrumb links, one on each line.'), |
| 85 |
'#default_value' => $bid ? $breadcrumb->paths : NULL |
'#default_value' => isset($breadcrumb->paths) ? $breadcrumb->paths : NULL, |
| 86 |
); |
); |
| 87 |
|
|
| 88 |
$form['help'] = array( |
$form['help'] = array( |
| 93 |
'#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."), |
'#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."), |
| 94 |
); |
); |
| 95 |
|
|
| 96 |
if (module_exists('token')) { |
// There is no token_help in core, but token_info has all the information in it. |
| 97 |
$form['help']['tokens'] = array( |
// Probably just need to wait until a token_help is available - or write our own? |
| 98 |
'#value' => theme('token_help', 'node'), |
// $form['help']['tokens'] = array( |
| 99 |
); |
// '#markup' => theme('token_help', 'node'), |
| 100 |
} |
// ); |
| 101 |
else { |
|
| 102 |
$form['help']['#description'] = t("To use dynamic placeholder tokens in your breadcrumb trails (the ID or title of the current node, for example), download and install the <a href='@token'>Token module</a> from Drupal.org.", array('@token' => 'http://www.drupal.org/project/token')); |
$form['help2'] = array( |
| 103 |
$form['help']['#collapsible'] = FALSE; |
'#type' => 'fieldset', |
| 104 |
$form['help']['#collapsed'] = FALSE; |
'#collapsible' => TRUE, |
| 105 |
} |
'#collapsed' => TRUE, |
| 106 |
|
'#title' => t('Special identifiers'), |
| 107 |
|
'#description' => t("The following identifiers can be used to achieve a special behavior. Identifiers should be added to the paths area in the following format: identifier|path.<br />For example: %pathauto_id|[ogname-raw]", array('%pathauto_id' => '<pathauto>')), |
| 108 |
|
); |
| 109 |
|
$form['help2']['tokens'] = array('#theme' => 'custom_breadcrumbs_help_identifiers'); |
| 110 |
|
|
| 111 |
$form['buttons']['submit'] = array( |
$form['buttons']['submit'] = array( |
| 112 |
'#type' => 'submit', |
'#type' => 'submit', |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
function custom_breadcrumbs_form_validate($form, &$form_state) { |
function custom_breadcrumbs_form_validate($form, &$form_state) { |
| 127 |
$path_count = count(explode("\n", $form_state['values']['paths'])); |
$path_count = count(explode("\n", trim($form_state['values']['paths']))); |
| 128 |
$title_count = count(explode("\n", $form_state['values']['titles'])); |
$title_count = count(explode("\n", trim($form_state['values']['titles']))); |
| 129 |
if ($title_count != $path_count) { |
if ($title_count != $path_count) { |
| 130 |
form_set_error(t('Every link path must have a matching title. There are !paths paths, and !titles titles.', array('!paths' => $path_count, '!titles' => $title_count))); |
$error_field = ($title_count < $path_count) ? 'titles' : 'paths'; |
| 131 |
|
form_set_error($error_field, t('Every link path must have a matching title. There are !paths paths, and !titles titles.', array('!paths' => $path_count, '!titles' => $title_count))); |
| 132 |
} |
} |
| 133 |
} |
} |
| 134 |
|
|