/[drupal]/contributions/modules/custom_breadcrumbs/custom_breadcrumbs.admin.inc
ViewVC logotype

Contents of /contributions/modules/custom_breadcrumbs/custom_breadcrumbs.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Oct 4 19:20:16 2009 UTC (7 weeks, 2 days ago) by mgn
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.2: +41 -24 lines
File MIME type: text/x-php
Updating HEAD for D7 development
1 <?php
2 // $Id: custom_breadcrumbs.admin.inc,v 1.1.2.5 2009/09/30 12:12:11 mgn Exp $
3
4 /**
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() {
13 $breadcrumbs = _custom_breadcrumbs_load_all_breadcrumbs(TRUE);
14
15 $header = array(t('Node type'), '');
16
17 $rows = array();
18 foreach ($breadcrumbs as $breadcrumb) {
19 $row = array();
20 $row[] = $breadcrumb->node_type . (!empty($breadcrumb->visibility_php) ? t(' with PHP snippet') : '');
21 $row[] = l(t('edit'), 'admin/build/custom_breadcrumbs/edit/'. $breadcrumb->bid);
22 $rows[] = $row;
23 }
24 if (count($rows) == 0) {
25 $rows[] = array(array('data' => t('No custom breadcrumbs have been defined.'), 'colspan' => 2));
26 }
27
28 $rows[] = array(array('data' => l(t('Add a new custom breadcrumb'), 'admin/build/custom_breadcrumbs/add'), 'colspan' => 2));
29
30 $build = array();
31 $build['breadcrumb_table'] = array('#markup' => theme('table', $header, $rows));
32
33 return $build;
34 }
35
36 /**
37 * Display an edit form for a custom breadcrumb record.
38 */
39 function custom_breadcrumbs_form() {
40 $bid = arg(4);
41 if (isset($bid)) {
42 $breadcrumb = _custom_breadcrumbs_load_breadcrumb($bid);
43 $form['bid'] = array(
44 '#type' => 'hidden',
45 '#value' => $bid,
46 );
47 }
48
49 $options = array();
50 $types = node_type_get_names();
51 foreach ($types as $type => $name) {
52 $options[$type] = $name;
53 }
54
55 $form['node_type'] = array(
56 '#type' => 'select',
57 '#title' => t('Node type'),
58 '#required' => TRUE,
59 '#options' => $options,
60 '#description' => t('The node type this custom breadcrumb trail will apply to.'),
61 '#default_value' => isset($breadcrumb->node_type) ? $breadcrumb->node_type : NULL,
62 );
63
64 $form['visibility_php'] = array(
65 '#type' => 'textarea',
66 '#title' => t('Breadcrumb visibility'),
67 '#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.'),
69 '#default_value' => isset($breadcrumb->visibility_php) ? $breadcrumb->visibility_php : '',
70 );
71
72 $form['titles'] = array(
73 '#type' => 'textarea',
74 '#title' => t('Titles'),
75 '#required' => TRUE,
76 '#description' => t('A list of titles for the breadcrumb links, one on each line.'),
77 '#default_value' => isset($breadcrumb->titles) ? $breadcrumb->titles : NULL,
78 );
79
80 $form['paths'] = array(
81 '#type' => 'textarea',
82 '#title' => t('Paths'),
83 '#required' => TRUE,
84 '#description' => t('A list of Drupal paths for the breadcrumb links, one on each line.'),
85 '#default_value' => isset($breadcrumb->paths) ? $breadcrumb->paths : NULL,
86 );
87
88 $form['help'] = array(
89 '#type' => 'fieldset',
90 '#collapsible' => TRUE,
91 '#collapsed' => TRUE,
92 '#title' => t('Placeholder tokens'),
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."),
94 );
95
96 // There is no token_help in core, but token_info has all the information in it.
97 // Probably just need to wait until a token_help is available - or write our own?
98 // $form['help']['tokens'] = array(
99 // '#markup' => theme('token_help', 'node'),
100 // );
101
102 $form['help2'] = array(
103 '#type' => 'fieldset',
104 '#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(
112 '#type' => 'submit',
113 '#value' => t('Submit'),
114 );
115 if ($bid) {
116 $form['buttons']['delete'] = array(
117 '#type' => 'submit',
118 '#value' => t('Delete'),
119 '#submit' => array('custom_breadcrumbs_form_delete'),
120 );
121 }
122
123 return $form;
124 }
125
126 function custom_breadcrumbs_form_validate($form, &$form_state) {
127 $path_count = count(explode("\n", trim($form_state['values']['paths'])));
128 $title_count = count(explode("\n", trim($form_state['values']['titles'])));
129 if ($title_count != $path_count) {
130 $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
135 function custom_breadcrumbs_form_submit($form, &$form_state) {
136 $breadcrumb = (object)$form_state['values'];
137 custom_breadcrumbs_save_breadcrumb($breadcrumb);
138 $form_state['redirect'] = 'admin/build/custom_breadcrumbs';
139 }
140
141 function custom_breadcrumbs_form_delete($form, &$form_state) {
142 _custom_breadcrumbs_delete_breadcrumb($form_state['values']['bid']);
143 $form_state['redirect'] = 'admin/build/custom_breadcrumbs';
144 }

  ViewVC Help
Powered by ViewVC 1.1.2