I just fixed a configuration issue on a production site built with Drupal 7, what I would rather call a design bug with Blog module in D7.

We had last month delivered a D7 based site to a client, with ability for various authorized users to create and maintain their blogs on the site using Drupal’s native Blog module. And in the morning today, I received an email from the client stating that one of the user’s had created 3 blog entries and everything works fine, except that when we visit the user’s individual blog page at:
http://example.com/blog/uid

(where uid was the user’s id), only a single blog post was being shown.

This surprised me a bit and my first impression was the other 2 blog entries might not have been published. When I checked it, all the blog posts were published. I then went into the Views administration section on the site assuming blog module might be using a View that would need configuration. But I found no view being used by Blog module for the users’ blog page, which clearly indicated Blog module was manually creating that page in code.

So next I went into the code for the Blog module, and immediately noticed the blog.pages.inc file there. I opened it, and the first function in the file was blog_page_user. The name chosen for the function was enough to indicate it was producing the blog page for an individual user.

There was this $query in that function:

 

  $nids = $query
    ->fields('n', array('nid', 'sticky', 'created'))
    ->condition('type', 'blog')
    ->condition('uid', $account->uid)
    ->condition('status', 1)
    ->orderBy('sticky', 'DESC')
    ->orderBy('created', 'DESC')
    ->limit(variable_get('default_nodes_main', 10))
    ->addTag('node_access')
    ->execute()
    ->fetchCol();

and I noticed this LIMIT clause from this query:

 

    ->limit(variable_get('default_nodes_main', 10))

This indicated that blog module was using the value of configuration variable default_nodes_main for deciding the number of blog posts to show on a user’s blog page. I first thought this might be the value of Number of RSS feeds to show at:
http://example.com/admin/config/services/rss-publishing

But found that value to be already 10. Then it appeared this variable would rather reflect the value of the option “Number of posts on front page” available at:
http://example.com/admin/config/system/site-information

And bingo, I hit the jackpot. That value was set to 1, increasing it to 10 showed all 3 blog posts on the user’s blog page.

Thinking about it now, I consider this a design bug in Drupal 7’s blog module. Number of posts to show on front page are almost always dependent upon theme (assuming you have built a custom theme for a client based on requirements and not using off the shelf theme packaged with Drupal or available from d.o).

In fact, for all of the sites we have done with Drupal for clients, we have made customized themes and number of posts on front page have been hard-coded in theme (the current site had 4). In other cases, I have mostly seen people using 1 or 2 posts on front page (not considering the sites where Drupal is primarily used as a blogging, discussion or news platform, which normally use value 10 for the configuration option).

As blog module author, I would have rather hard-coded value 10 for the number of posts to show on a user’s blog, or better still, made it configurable through the options available here:
http://example.com/admin/structure/types/manage/blog

But then, design decisions are almost always subjective. What seems a best practice to one might appear a bug from another developer’s viewpoint, it would be interesting to see how many people in Drupal community found this behavior of Blog module counter-intuitive.