Insert this code at line 175 of modules/blog/blog.module to create a blog module tab at user/%user. Remember to run update.php after saving the changes to the file.

$items['user/%user/blog'] = array(
'title' => 'Blog',
'page callback' => 'blog_page_user',
'page arguments' => array(1),
'access callback' => 'blog_page_user_access',
'access arguments' => array(1),//array('access content'),
'type' => MENU_LOCAL_TASK,
'file' => 'blog.pages.inc',
'weight' => '15',
);

You can change the tab's placement by adjusting the weight.

Here's a pic of what it looks like.

CommentFileSizeAuthor
#12 blog-user-tab-270457-012.patch612 byteskarschsp
blogtab.PNG151.54 KBmarkpenny
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

markpenny’s picture

Sorry. Let me clean up that code a little. Same instructions.

$items['user/%user/blog'] = array(
'title' => 'Blog',
'page callback' => 'blog_page_user',
'page arguments' => array(1),
'access callback' => 'blog_page_user_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => '15',
'file' => 'blog.pages.inc',
);
mercmobily’s picture

Hi,

I think this patch is awesome. Any chances of getting this committed to D6?

Merc.

markpenny’s picture

That would be nice. I'm not in the Drupal loop, so you'd have to go higher up. Would you like to take charge of lobbying?

mercmobily’s picture

Hi,

I would be happy to create a proper patch (it would go to the blog.module module).

The patch would need to add a checkbox somewhere for the blog module (where?), and if it's active, it would need to add the tab. It really is a trivial change.

I would be happy to do the patch against D6 if they told me that there is a chance of being accepted.

Merc.

lilou’s picture

Version: 6.2 » 7.x-dev

Feature request go to CVS/HEAD.

mercmobily’s picture

Hi,

I have looked into this issue a *lot*. I now realise that there is more than one issue in terms of having the full blog in the tab -- and it's enough of a headache to deserve a "no" from Drupal Core. I am saying this because if *I* were part of Drupal core, I'd refuse this patch.
For example:

* The link to the person's blog in general is to /blog/N and not /user/blog/N.

* It would tend to be confusing, having blogs in two different spots.

I am developing a web site where both blogs *and* blog entries are within a user's tab. But there's a lot of aliasing happening, and it's anything but simple.

Merc.

markpenny’s picture

I'm not quite sure I follow. No doubt you know what you're talking about. It's just a little beyond my current expertise.

From my point of view, there doesn't seem to be a problem with the patch as is.

Incidentally, I'm thinking of putting together a set of tab patches. You can check my profile to see what I've done so far. To date, each patch has to be added manually to the associated module file. I'd like to build something that can be installed separately from the modules it patches to. I'm thinking of calling it Tabulator or Tab-u-later or something. The simplest version would just be a module file with the patches commented out for selective enabling. A more advanced version would add an item to site configuration. Interested in working on that idea? I see you've got a fair bit of experience with contributed modules. I reckon you'd know what to do and how to do it.

mercmobily’s picture

Hi,

My comment in #6 is flawed. Sorry.
I was referring to the possibility that an administrator might possibly want to have their blogs ONLY in the user's profile. I actually managed... but what a struggle. I had to:

* Define two new menu entries:

  $items['user/%user/blog/%node'] = array(
    'title' => 'Blog',
    'page callback' => 'blog_caged_blog_page',
    'page arguments' => array(1,3),
    'access callback' => 'blog_page_user_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => '15',
  );

  $items['user/%user/blog'] = array(
    'title' => 'My blog',
    'page callback' => 'blog_caged_blog_page_user',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'file' => 'blog.pages.inc',
    'type' => MENU_LOCAL_TASK,
  );

* Define the function to feed these callbacks:

function blog_caged_blog_page_user($account){
  global $user;

  if( ! _blog_post_exists($account) ){

    $msg_1=t("No blog posts! ");
    if($user->uid == $account->uid){
      $msg_2=t('Add a blog entry <a href="!url">Now!</a>', array('!url' => url('node/add/blog') ));
    }
    return $msg_1 . $msg_2;
  }

  return blog_page_user($account);
}

function blog_caged_blog_page($user,$node){

  // Check that it's a user's blog entry we are talking about. This is to
  // prevent this from working for ANY kind of node, which would SUCK
  // as you'd be able to pull any content into the users' page
  if($node->type != 'blog' || $node->uid != $user->uid){
    drupal_not_found();
  }

  // Set the title and return the page!
  drupal_set_title($node->title);
  return node_show($node,NULL);
}

* KILL the default URLs. this is just to be tidy.

function blog_caged_menu_alter(&$callback){

  // Kill existing URLs, which will never get used. IMPORTANT:
  // make absolute sure you set the right redirections for outbound links!
  $callback['blog/%user_uid_optional']['page callback']='drupal_not_found';
  $callback['blog']['page callback']='drupal_not_found';
}

And then change the outbound links in settings.php:

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  if (preg_match('|^node/([0-9]*)$|', $path, $matches)) {
    $n=db_fetch_object(db_query("SELECT n.nid,n.type, u.name FROM {node} n LEFT JOIN {users} u on u.uid = n.uid WHERE n.nid = %d ",$matches[1]));
    if($n){
      $type=$n->type;
      $nid=$n->nid;

      // BLOGS     
      if($type == 'blog'){
        $user=$n->name;
        $path="user/$user/blog/$nid";
      }
    }

  // Case #2: turn blog/99 into users/admin/blog
  if (preg_match('|^blog/([0-9]*)$|', $path, $matches)) {
    $uid = $matches[1];
    $res=settings_lookup_user_name_by_uid($uid);
    if($res){
      $res=urlencode($res);
      $path="user/$res/blog";
    }

  }
}

function settings_lookup_user_name_by_uid($uid){
  static $users;

  if(!$users[$uid]){
    $name= db_result(db_query("SELECT name FROM {users} WHERE uid =%d",$uid));
    $users[$uid]=$name;
  }
  return $users[$uid];
}

After _all_ of this messy trouble, you have basically *caged* the blogs in the users' page. I am developing a site that is _all_ about user pages... and doing this makes sense.

I am not sure if this is even relevant. I think your aim is different: it's to *just* show the blog entries in the user's page. However, the minute you click on one of them, that's it.

I totally support your patch. but... you do realise that you can ontain what you want by just taking the right bits from my code above? Again, it would probably make sense for the blog module to have it... but this _can_ be done as a third party module. Just a t thought.

Bye,

Merc.

Dave Reid’s picture

I'm in support of this and think we should *only* support user/%user/blog paths and not blog/%user. We don't even have to make it a tab, it can be a callback. Using the user/%user/blog makes it easier for modules like Sub-path URL alias to automatically extend the alias of user/%user to it's sub-path 'blog'.

greggles’s picture

Version: 7.x-dev » 8.x-dev

I like this idea too, but it's probably an 8.x change now.

Dave Reid’s picture

Issue tags: +pathauto

Tagging as this would help us remove redundant code in pathauto.

karschsp’s picture

Assigned: markpenny » karschsp
Status: Active » Needs review
FileSize
612 bytes

Patch attached. Go testbot go!

greggles’s picture

Title: Blog tab at user/%user (account) » Move blog url to user/%user/blog (account)
deekayen’s picture

Project: Drupal core » Blog
Version: 8.x-dev » 8.x-2.x-dev
Component: blog.module » User interface
nevergone’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Outdated issue.