I have added some already requested features and fixed some bugs:

  • Bugfix: drupal_get_title() returns htmlspecialchars that had to be recoded (to avoid titles like "Tools & more").
  • (Bug)fix: The "manage all favorites" permission could be set but was not used. So I commented it out for now.
  • Feature: Changed the "path" column to 2048 chars (instead of 255). I am aware that there might even be longer queries, but hey.
  • Feature: Instead of using the page title in a hidden field, it can now be modified by the user since I turned it into a text field. The field can be designed by css if desired; by default it sets to 90% of parent's width. Both the text field an the submit button are now in a collapsed field to easy annoyment of the clumsy form elements.
  • Feature: Hovering over the "x" (deletion link) now makes clear that this IS a deletion link. You never know what user's might not know...

Attached my version of the module (be aware that, lazy me, did not implement an update function for the DB change. Feel free to contribute that yourself) and both diffs:

--- favorites.module.original	So 28. Feb 18:36:54 2010
+++ favorites.module	Do 17. Mrz 18:08:20 2011
@@ -12,7 +12,7 @@
  * Implementation of hook_perm().
  */
 function favorites_perm() {
-  return array('manage own favorites', 'manage all favorites');
+  return array('manage own favorites'); // this is not implemented yet: , 'manage all favorites');
 }
 
 /*
@@ -53,7 +53,7 @@
  */
 function favorites_remove_favorite($favorite) {
   global $user;
-  $access = (user_access('manage own favorites') && $user->uid == $favorite->uid) || user_access('manage all favorites');
+  $access = (user_access('manage own favorites') && $user->uid == $favorite->uid); // no admin page implemented yet! || user_access('manage all favorites');
   if (!$access) {
     drupal_set_message(t("You do not have permission to remove this favorite."));
     drupal_goto();
@@ -96,9 +96,9 @@
 function favorites_user_block() {
   global $user;
   $output = '';
-  $output .= drupal_get_form('favorites_add_favorite_form');
   $favorites = favorites_load_favorites($user->uid);
   $output .= theme('favorites', $favorites);
+  $output .= drupal_get_form('favorites_add_favorite_form');
   $block['subject'] = t('My Favorites');
   $block['content'] = $output;
   return $block;
@@ -114,7 +114,22 @@
   $destination = str_replace('destination=', '', $destination);
   foreach ($favorites as $favorite) {
     $query = array();
-    $items[]= l($favorite->title, $favorite->path, array('query' => $favorite->query)) . ' ' . l('x', 'favorites/remove/' . $favorite->fid, array('class' => 'favorites-remove', 'query' => array('token' => $favorite->token, 'destination' => $destination)));
+    $items[]= l($favorite->title, $favorite->path, array('query' => $favorite->query)) 
+        . ' ' 
+        . l(
+            'x', 
+            'favorites/remove/' . $favorite->fid, 
+            array(
+                'class' => 'favorites-remove', 
+                'query' => array(
+                    'token' => $favorite->token, 'destination' => $destination
+                ),
+                'attributes' => array(
+                    'title' => t('delete this item'),
+                ),
+            )
+        )
+    ;
   }
   return theme('item_list', $items);
 }
@@ -135,9 +150,33 @@
 
 function favorites_add_favorite_form() {
   global $user;
-  $form['submit'] = array(
+  $title = htmlspecialchars_decode(drupal_get_title());
+  if (empty($title)) {
+    $title = check_plain(variable_get('site_name', 'Home'));
+  }
+
+  $title = strip_tags($title);
+  // add a collapsible container
+  $form['add'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+    '#title' => t('add this page'),
+  );
+  $form['add']['title'] = array(
+    '#type' => 'textfield',
+    '#size' => 20,
+    '#maxlength' => 255,
+    '#default_value' => $title,
+    '#attributes' => array(
+      'style' => 'width: 90%',
+      'class' => 'favorites-add-textfield',
+    ),
+  );
+
+  $form['add']['submit'] = array(
     '#type' => 'submit',
-    '#value' => t("Add to my favorites"),
+    '#value' => t("Add"),
     '#submit' => array('favorites_add_favorite_form_submit'),
   );
   $form['path'] = array(
@@ -150,17 +189,6 @@
     '#value' => drupal_query_string_encode($_GET, array('q')),
   );
 
-  $title = drupal_get_title();
-  if (empty($title)) {
-    $title = check_plain(variable_get('site_name', 'Home'));
-  }
-
-  $title = strip_tags($title);
-  $form['title'] = array(
-    '#type' => 'value',
-    '#value' => $title,
-  );
-
   //Preserve the current path with query string.
   $destination = drupal_get_destination();
   $form['#redirect'] = array($_GET['q'], drupal_query_string_encode($_GET, array('q')));
--- favorites.install.original	So 28. Feb 18:36:54 2010
+++ favorites.install	Do 17. Mrz 18:44:56 2011
@@ -37,19 +37,19 @@
         'not null' => TRUE,
       ),
       'path' => array(
-        'decription' => "The favorited path",
+        'description' => "The favorited path",
         'type' => 'varchar',
-        'length' => 255,
+        'length' => 2048,
         'not null' => TRUE,
       ),
         'title' => array(
-        'decription' => "The title of the favorite",
+        'description' => "The title of the favorite",
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
       ),
         'query' => array(
-        'decription' => "The query parameters for the saved path.",
+        'description' => "The query parameters for the saved path.",
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,

Comments

doitDave’s picture

Status: Active » Needs review

issue status corrected

doitDave’s picture

Version: 6.x-1.2 » 6.x-1.3
Status: Needs review » Fixed

Fixed with the 1.3 release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.