Wednesday, August 12, 2009

Administer specific content types in drupal using views

As we know site content can be edited/deleted on admin/content/node page but this page is accessible to only those users whose have been granted permission for 'administer nodes' from admin/user/permissions page. Sometimes we want to give users edit/delete permissions for specific content types. Say we have a new Editor type role who should have add/edit/delete permission to some specific content types blogs, story. If we grant 'administer nodes' permission to Editor role, Users of editor type role will be able to add/edit/delete all type of nodes and will have complete access to admin/content/node page so we can not grant this permission to Editor.
First we need to assign following specific permissions to editor role from admin/user/permissions page
  • create blog entries
  • delete any blog entry
  • delete own blog entries
  • edit any blog entry
  • edit own blog
  • and add permissions for story content type or other content types as per your requirement.
Now While viewing a node of blog or story content type Editor will be able to edit these particular node types and can directly access edit page for these nodes from node/(nid)/edit. But our requirement is bit different we want a page like admin/content/node where Editor will be able to view list of story and blog nodes and can edit/delete both node types.
We are going to use views to resolve this as we have already assigned permission to editor for these two type of nodes the only one thing left is to create a page like admin/content/node.
So here we go.....

  1. Create a new view from admin/build/views/add. Enter View name, View description as per your need . select Node from view type. See image below
  2. Click next
  3. Add 'page' type display. See image below.
  4. Add path 'editor/page-blog/edit' under page settings. you can choose your own path where this view will be rendered.
  5. Fields : Select Node Title, Node Edit Link, Node Post date. See image below
  6. Basic Settings : Set the basic settings for following. See the image below
  7. Basic Settings : style type: table, Use pager: yes , etc
  8. Basic Settings : Check sortable for Title and Post date style type settings. See the image below.
  9. Now select filters Node published(exposed), Node title (exposed) and Node type(exposed). If you are selecting Filter:Node type exposed you have to be very careful while selecting the exposed settings. Must see the screen shot for Node type: exposed after point 22.
  10. When you press expose button for Node:Published you will see following fields. See the screen shot below select highlighted radio and check box.
  11. Node:Title exposed settings screen shot is below. Select the settings as highlighted.
  12. Select Node types Blog entry and story For filter:Node types. See the screen shot below for exposed settings.
Save the view and goto URL you have specified for Views: Page settings :path . For this case I have specified editor/page-blog/edit . By mistake I've specified path editor/page-blog/edit instead of editor/story-blog/edit. . This path has nothing to do with data rendered by view, but it looks better if we specify a sensible path depending on page data.

See the screen shot below for the view just created.


We can add one more field Node type as well which also could be made sortable like Title and Post date.

Drupal 6 SEO | Must have modules

These are the modules, I think must be installed for SEO.

PathAuto
A must-have module for all Drupal installations. Helps creating SEO friendly URL for any node type, Taxonomy, User pages.

XML Sitemap
XML sitemap automatically creates a sitemap that conforms to the sitemaps.org specification. This helps search engines keep their search results up to date.

Page Title
Allows to set dynamic page titles for different nodes.

Nodewords (AKA Meta Tags)
Allows you to specify meta keywords and descriptions for each page (or node) as well as the homepage. It also supports GeoURLs .

Global Redirect
Provides features like remove the trailing slash from requests. so that dreaded duplicate content is avoided that search engines seem to hate. It creates 301 redirects for two potentially duplicative URLs. checks for case sensitive urls as well.

Saturday, August 1, 2009

Flow of drupal

I assume many of drupal beginners will be curious to know about flow of drupal as I was When I started learning drupal a few years back. How execution takes place with in drupal From a request sent by a browser to data returned to the browser.
I'll not be going into complete details, instead would be covering the overview of drupal execution.

When a request for a page is sent by a browser , this request is received by the server hosting a drupal site. Suppose a request is sent for the page http://drupal.org/user/1 this request is received by drupal installation directory as URL user/1.
We have an .htaccess file inside drupal installation directory which is read on every request.
There is a rule ( RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] ) written almost at the bottom of this file which redirects the coming request to index.php file with URL request as a parameter. which is q=user/1 is this case.
NOTE: This request is available with in drupal in $_GET['q'] variable.
If you open index.php file you find a file bootsrap.inc being included and some other functions written. From here actual drupal exection starts.

In index.php file drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) fuction is called which is defined inside includes/bootstrap.inc file. Drupal bootstraps process is executed on every request by going through various bootstrap phases. These phases are explained in bootstrap.inc file.

  • DRUPAL_BOOTSTRAP_CONFIGURATION : This phase Initializes internal configuration array and establishes the base URL ($base_url) of the site.
  • DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE: This phase returns the requested page if the page has been already cached . once the page is returned the further execution is terminated. Mostly for the anonymous users we can have some static pages which can be cached for the better performance.
  • DRUPAL_BOOTSTRAP_DATABASE : This phase Initializes the default database.
  • DRUPAL_BOOTSTRAP_ACCESS :In Access control phase drupal denies access to hosts which were banned.
  • DRUPAL_BOOTSTRAP_SESSION: Sessions are initialized or reestablished in the session phase. The global $user object representing the current user is also initialized here.
  • DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE : In this phase drupal goes through a lot of execution unlike DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE phase to determine whether to serve the request from page cache or not. This includes merging settings from the database into the array that was created during the initialize configuration phase and loading or parsing module code. If the session indicates that the request was issued by an anonymous user and page caching is enabled, the page is returned from the cache and execution stops.


  • DRUPAL_BOOTSTRAP_LANGUAGE : Drupal’s multilingual support is initialized and a decision is made as to which language will be used to serve the current page based on site and user settings. Drupal supports several alternatives for determining language support, such as path prefix and domain-level language negotiation.

  • DRUPAL_BOOTSTRAP_PATH : At the path phase, code that handles paths and path aliasing is loaded. This phase enables human-readable URLs to be resolved and handles internal Drupal path caching and lookups.

  • DRUPAL_BOOTSTRAP_FULL: This phase completes the bootstrap process by loading a library of common functions, theme support, and support for callback mapping, file handling, Unicode, PHP image toolkits, form creation and processing, mail handling, automatically sortable tables, and result set paging.
    Drupal’s custom error handler is set, and all enabled modules are loaded. Finally, Drupal fires the init hook, so that modules have an opportunity to be notified before official processing of the request begins.
    Once Drupal has completed bootstrapping, all components of the framework are avail-
    able. It is time to take the browser’s request and hand it off to the PHP function that will
    handle it. The mapping between URLs and functions that handle them is accomplished using a callback registry that takes care of both URL mapping and access control. Modules register their callbacks using the menu hook.
    When Drupal has determined that there exists a callback to which the URL of the browser request successfully maps and that the user has permission to access that callback, control is handed to the callback function.
After the bootstrap process is completed code for returning the requested data is executed depending on the requested url.
In index.php there's a function $return = menu_execute_active_handler();
menu_execute_active_handler() function Execute the page callback associated with the current path.

For example if request for "http://drupal.org/user/1" is received. In user.module file on line 1051 drupal6.12 we have an menu item defined ,

$items['user/%user_uid_optional'] = array(
'title' => 'My account',
'title callback' => 'user_page_title',
'title arguments' => array(1),
'page callback' => 'user_view',
'page arguments' => array(1),
'access callback' => 'user_view_access',
'access arguments' => array(1),
'parent' => '',
'file' => 'user.pages.inc',
);

The requested url (user/1)is mapped to "user/%user_uid_optional". Access callback function user_view_access() checks if the requested path is accessible to current user or not and page callback function user_view() defined in user.pages.inc file returns the requested data.


1. Start (Browser's request is received)
2. Drupal bootstrap Phases completed includes DB connection, session setup, language setup, library function loading, Enabled modules loading etc is done.
3. menu_execute_active_handler function is called.
4. If site is offline, drupal_site_offline() is returned and exit
5. If requested URL not found, drupal_not_found() returned and exit
6. If requested url is not accessible to the current user, drupal_access_denied() is returned and exit
7. Page callback fuction is called mapped to requested URL which returns requested data .

A few people might be thinking why this URL has been taken as an example. http://drupal.org/user/1 is a user page of drupal founder Dries Buytaert on drupal.org .