Skip to content

Commit 7e09c9c

Browse files
committed
Phasing out the old slug system.
1 parent 864dc8e commit 7e09c9c

File tree

6 files changed

+41
-279
lines changed

6 files changed

+41
-279
lines changed

ding_breadcrumbs/ding_breadcrumbs.module

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
2-
32
/**
4-
* @file ding_breadcrumbs.module
5-
* Handles the generation and loading of nodes from "slugs",
6-
* small bits of text, suitable for use in URLs.
3+
* @file
4+
* Provides custom breadcrumbs for Ding pages.
75
*/
86

97
/**
@@ -41,17 +39,15 @@ function ding_breadcrumbs_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
4139
else {
4240
if (isset($node->field_library_ref[0]['nid'])) {
4341
$trail[] = l(t('Libraries'), 'biblioteker');
44-
$library = node_load($node->field_library_ref[0]['nid']);
45-
$trail[] = l($library->title, 'node/' . $library->nid);
42+
$nid = $node->field_library_ref[0]['nid'];
43+
44+
$trail[] = l($library->title, 'node/' . $nid);
4645

47-
// Slugs are generated separately from library nodes and consequently
48-
// may not be set. Default to nid.
49-
$library_id = ($library->slug) ? $library->slug : $library->nid;
5046
if ($node->type == 'article') {
51-
$trail[] = l(t('Blog'), 'biblioteker/' . $library_id . '/blog');
47+
$trail[] = l(t('Blog'), 'node/' . $nid . '/blog');
5248
}
5349
elseif ($node->type == 'event') {
54-
$trail[] = l(t('Events'), 'biblioteker/' . $library_id . '/arrangementer');
50+
$trail[] = l(t('Events'), 'node/' . $nid . '/arrangementer');
5551
}
5652
}
5753
}

ding_event/ding_event.module

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* @file
54
* Module for handling event nodes.
@@ -65,13 +64,8 @@ function ding_event_theme() {
6564
function ding_event_views_pre_render(&$view) {
6665
// When the event list is being displayed on a library page...
6766
if ($view->name == 'event_list' && $view->current_display == 'panel_pane_2') {
68-
// Generate the link to the library's event page
69-
$id = ding_library_get_slug($view->args[0]);
70-
if (!$id) {
71-
// No slug? Fall back to nid
72-
$id = $view->args[0];
73-
}
74-
$url = url('biblioteker/' . $id . '/arrangementer');
67+
// Generate link to the library's event page.
68+
$url = url('node/' . $view->args[0] . '/arrangementer');
7569

7670
// Replace the URL in the more link to point at the library's event
7771
// page instead of the global one.

ding_library/ding_library.admin.inc

+1-114
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
2-
32
/**
4-
* @file ding_library.admin.inc
3+
* @file
54
* Admin forms, page callbacks and related functions.
65
*
76
* Much of this stuff is a taken from the scaffolding example module.
@@ -166,115 +165,3 @@ function theme_ding_library_admin_ordering_form($form) {
166165
return $output;
167166
}
168167

169-
/**
170-
* Slug editing form.
171-
*/
172-
function ding_library_admin_slugs_form(&$form_state) {
173-
// Confirmation form for changing existing slugs. The storage array
174-
// is set by the submit handler, and as long as it is non-empty, we're
175-
// returned to the form.
176-
if (!empty($form_state['storage']['slug_changes'])) {
177-
$changes_text = array();
178-
foreach ($form_state['storage']['slug_changes'] as $change) {
179-
$changes_text[] = t('Change slug for %library from !old to !new', array(
180-
'%library' => $change['title'],
181-
'!old' => '<tt>' . check_plain($change['old_slug']) . '</tt>',
182-
'!new' => '<tt>' . check_plain($change['new_slug']) . '</tt>',
183-
));
184-
}
185-
186-
return confirm_form(array(), t('Please confirm these slug changes'), $_GET['q'], theme('item_list', $changes_text), t('Confirm'), t('Cancel'));
187-
}
188-
189-
// Grab all the library nodes with their weight.
190-
$query = db_query("
191-
SELECT n.nid, n.title, p.value AS slug FROM {node} AS n
192-
LEFT JOIN {purl} AS p ON (p.id = n.nid AND provider = 'ding_library')
193-
WHERE n.type = 'library'
194-
ORDER BY n.title;
195-
");
196-
197-
$existing = array();
198-
$form = array();
199-
200-
$form['warning'] = array(
201-
'#prefix' => '<div class="warning">',
202-
'#value' => t("Here you can edit the identifying part of a library's URL, called “slugs”. Be aware that changing the existing slugs will URLs to change, resulting in dead links."),
203-
'#suffix' => '</div>',
204-
);
205-
206-
$form['records']['#tree'] = TRUE;
207-
while ($row = db_fetch_object($query)) {
208-
$form['records'][$row->nid] = array(
209-
'#type' => 'textfield',
210-
'#title' => $row->title,
211-
'#default_value' => $row->slug,
212-
);
213-
// Add the existing slugs to an array, so we'll be able to detect
214-
// overwriting in the validation.
215-
if (!empty($row->slug)) {
216-
$existing[$row->nid] = $row->slug;
217-
}
218-
}
219-
220-
$form['existing_slugs'] = array(
221-
'#type' => 'value',
222-
'#value' => $existing,
223-
);
224-
225-
$form['submit'] = array(
226-
'#type' => 'submit',
227-
'#value' => t('Save changes'),
228-
);
229-
230-
return $form;
231-
}
232-
233-
/**
234-
* Submit handler for the slug editing form.
235-
*/
236-
function ding_library_admin_slugs_form_submit($form, &$form_state) {
237-
// If the there's slug changes in the storage array, it means that
238-
// we've been through the confirmation form, and should now proceeed
239-
// to change the slugs in the database.
240-
if (isset($form_state['storage']['slug_changes'])) {
241-
foreach ($form_state['storage']['slug_changes'] as $change) {
242-
purl_save(array(
243-
'id' => $change['nid'],
244-
'provider' => 'ding_library',
245-
'value' => $change['new_slug'],
246-
));
247-
248-
// Unset the storage, so we'll won't get the confirmation page again.
249-
unset($form_state['storage']);
250-
return;
251-
}
252-
}
253-
254-
$slug_changes = array();
255-
256-
foreach ($form_state['values']['records'] as $nid => $slug) {
257-
if (!empty($slug)) {
258-
if (isset($form_state['values']['existing_slugs'][$nid]) && $form_state['values']['existing_slugs'][$nid] != $slug) {
259-
// Existing slug is being changed, store the changes so we can
260-
// create a confirmation form with it.
261-
$slug_changes[$nid] = array(
262-
'nid' => $nid,
263-
'title' => $form['records'][$nid]['#title'],
264-
'old_slug' => $form_state['values']['existing_slugs'][$nid],
265-
'new_slug' => ding_library_slugify($slug),
266-
);
267-
}
268-
else {
269-
// Save the newly added slug via PURL.
270-
purl_save(array(
271-
'id' => $nid,
272-
'provider' => 'ding_library',
273-
'value' => ding_library_slugify($slug),
274-
));
275-
}
276-
}
277-
}
278-
$form_state['storage']['slug_changes'] = $slug_changes;
279-
}
280-

ding_library/ding_library.info

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies[] = "location"
1212
dependencies[] = "node"
1313
dependencies[] = "office_hours"
1414
dependencies[] = "page_manager"
15-
dependencies[] = "purl"
15+
dependencies[] = "panels_subsites"
1616
dependencies[] = "rules"
1717
dependencies[] = "strongarm"
1818
dependencies[] = "views_content"
@@ -38,10 +38,6 @@ features[rules_categories][] = "ding_library"
3838
features[variable][] = "ant_library"
3939
features[variable][] = "comment_library"
4040
features[variable][] = "content_extra_weights_library"
41-
features[variable][] = "gmap_default"
42-
features[variable][] = "gmap_markermanager"
43-
features[variable][] = "gmap_mm_type"
44-
features[variable][] = "gmap_node_markers"
4541
features[variable][] = "language_content_type_library"
4642
features[variable][] = "location_defaultnum_library"
4743
features[variable][] = "location_geocode_dk"

ding_library/ding_library.install

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
2-
32
/**
4-
* @file ding_library.install
3+
* @file
54
* Installation and upgrade hooks for the ding_library module.
65
*/
76

@@ -192,3 +191,32 @@ function ding_library_update_6007() {
192191
db_add_index($ret, 'ding_library', 'branch_id', array('branch_id'));
193192
return $ret;
194193
}
194+
195+
/**
196+
* Enable panels_subsites.
197+
*/
198+
function ding_library_update_6008() {
199+
module_disable(array('purl'));
200+
drupal_install_modules(array('panels_subsites'));
201+
}
202+
203+
204+
/**
205+
* Migrate from our old slugs to panels_subsites.
206+
*/
207+
function ding_library_update_6009() {
208+
$old_slugs = db_query('
209+
SELECT p.id AS nid, p.value AS slug, n.type AS node_type
210+
FROM purl AS p
211+
INNER JOIN node AS n ON (n.nid = p.id)
212+
');
213+
214+
while ($row = db_fetch_object($old_slugs)) {
215+
drupal_write_record('panels_subsites_slugs', $row);
216+
}
217+
218+
// Get rid of the PURL modules.
219+
//drupal_uninstall_module('purl_test');
220+
//drupal_uninstall_module('purl');
221+
}
222+

0 commit comments

Comments
 (0)