Drupal 6 port with new "Edit bookmark title" feature

Valeratal - November 26, 2008 - 19:05
Project:Click2Bookmark
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

?

#1

Alan D. - December 10, 2008 - 04:15
Version:5.x-1.4» 5.x-1.x-dev

I was about to write my own for a Drupal 6 project, then found this. Saved a few hours work, nice.

I updated the 5-1.4 to 6 then patched this against head. The zip is this version minus the new internal views extension module. Testing has only been done using AJAX disabled, and has been fairly limited.

The patch is against head. I've had problems with patches generated using eclipse on windows, so use with care.

PS: Since almost 50% of Drupal installs use views, I think adding the views code directly into the core module is best. This saves cluttering up the systems table!

AttachmentSize
click2bookmark-5-6.patch 11.96 KB
click2bookmark.zip 8.27 KB

#2

Alan D. - December 10, 2008 - 11:55
Title:version for drupal 6x ?» Drupal 6 port with new "Edit bookmark title" feature
Status:active» needs review

When looking at the update to Drupal 6, the first item that I bookmarked had a very non-descriptive title, and the second node had the same title as the first. Duh.

So here is some code that allows editing of the bookmarks title. I can backport to Drupal 5 if your interested.

<?php

# new menu item
 
$items['bookmark/edit/%click2bookmark'] = array(
   
'title'    => t('Update bookmark'),
   
'page callback' => 'drupal_get_form',
   
'page arguments' => array('click2bookmark_bookmarks_edit', 2),
   
'access arguments' => array(CLICK2BOOKMARK_PERM),
  );

# menu load callback, the %click2bookmark above
/**
* This loads the bookmark record, restricted to the
* bookmarks belonging to the currently logged in user.
*
* @param int $c2bid
* @return object
*   The loaded bookmark or FALSE if not found.
*/
function click2bookmark_load($c2bid) {
  global
$user;
  return
db_fetch_object(db_query('SELECT * FROM {click2bookmark} WHERE c2bid = %d AND uid = %d', $c2bid, $user->uid));
}

/**
* Edit form
*
* @param array $form_state
* @param object $bookmark
* @return array
*/
function click2bookmark_bookmarks_edit($form_state, $bookmark) {
 
$form = array();
 
$form['path'] = array(
   
'#type' => 'item',
   
'#title' => t('Path'),
   
'#value' => $bookmark->path,
  );
 
$form['c2bid'] = array(
   
'#type' => 'value',
   
'#value' => $bookmark->c2bid,
  );
 
$form['title'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Title'),
   
'#default_value' => $bookmark->title,
  );
 
$form['submit'] = array(
   
'#type' => 'submit',
   
'#value' => t('Save'),
   
'#required' => TRUE,
   
'#submit' => array('click2bookmark_bookmarks_edit_submit'),
  );
  return
$form;
}

/**
* Edit submit handler
*
* @param array $form
* @param array $form_state
*/
function click2bookmark_bookmarks_edit_submit($form, &$form_state) {
 
db_query("UPDATE {click2bookmark} SET title = '%s' WHERE c2bid = %d", $form_state['values']['title'], $form_state['values']['c2bid']);
 
drupal_set_message(t('Bookmark updated'), 'status');
 
$form_state['redirect'] = 'bookmark/view';
}

# Updated bookmark listing
function theme_click2bookmark_bookmarks_view($bookmark_list = array()) {
  global
$user;
 
$rows = array();
 
$header = array(t('Bookmarks'), array('data' => t('Action'), 'colspan' => 2));
  if (
count($bookmark_list) > 0) {
    foreach(
$bookmark_list as $bookmark) {
     
$rows[] = array(
       
l($bookmark['title'], $bookmark['path'], array('class' => 'click2bookmark-row-link')),
       
l(t('edit'), 'bookmark/edit/'.$bookmark['id']),
       
l(t('delete'), 'bookmark/del/'.$bookmark['id']),
        );
    }
  } else {
   
$rows[] = array('data' => array(t('< bookmark list is empty >')), 'colspan' => 3);
  }
  return
theme('table', $header, $rows);
}
?>

#3

Valeratal - December 18, 2008 - 06:44

thank, I try it

 
 

Drupal is a registered trademark of Dries Buytaert.