How does drupal work
This presentation is the property of its rightful owner.
Sponsored Links
1 / 12

How does Drupal Work? PowerPoint PPT Presentation


  • 80 Views
  • Uploaded on
  • Presentation posted in: General

Information Systems 337 Prof. Harry Plantinga. How does Drupal Work?. Drupal Modules. Defining a Module: guess how? Create a directory, e.g. /sites/all/modules/annotate Create a file annotate.info : name = Annotate description = Allows users to annotate nodes. package = Example

Download Presentation

How does Drupal Work?

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


How does drupal work

Information Systems 337

Prof. Harry Plantinga

How does Drupal Work?


Drupal modules

Drupal Modules

  • Defining a Module: guess how?

    • Create a directory, e.g. /sites/all/modules/annotate

    • Create a file annotate.info:

      name = Annotate

      description = Allows users to annotate nodes.

      package = Example

      core = "6.x"


Hooks

Hooks

  • Module system based on the concept of hooks

  • Hook:

    • a PHP function named foo_bar()

    • foo: name of the module

    • bar: name of the hook

  • Extending Drupal:

    • a module extends Drupal by implementing hooks


Hooks1

Hooks

  • An event happens, e.g. a user logs into the site.

  • Drupal fires the "user hook".

  • That means each module's user hook function will be called:

    • comment_user()

    • node_user()

    • locale_user()

    • myCustomModule_user()

  • Documented on Drupal.org


Examples

Examples

  • Example: hook_access($op, $node, $account)

    • this hook allows modules to limit access to the node types they define

    • $op: create, delete update, view

    • returns TRUE, FALSE, or NULL (don't override settings in the node_access table

    • to override in "example" module, you would implement example_access()


Add a menu entry

Add a Menu Entry

/**

* Implementation of hook_menu()

*/

function annotate_menu() {

$items['admin/settings/annotate'] = array(

'title' => 'Annotation settings',

'description' => 'Change how annotations behave',

'page callback' => 'drupal_get_form',

'page arguments' => array('annotate_admin_settings'),

'access arguments' => array('administer site configuration'),

'type' => MENU_NORMAL_ITEM,

);

return $items;

}


Define settings form

Define Settings Form

/**

* Define the settings form.

*/

function annotate_admin_settings() {

$form['annotate_node_types'] = array(

'#type' => 'checkboxes',

'#title' => 'Users may annotate these node types'

'#default_value' =>

variable_get('annotate_nodetypes', array('page')),

'#description' => 'A text field will be available on these node types to make user-specific notes.',

);

$form['array_filter'] = array('#type' => 'hidden');

return system_settings_form($form);

}


Add annotation to node

Add Annotation to Node

/**

* Implementation of hook_nodeapi().

*/

function annotate_nodeapi(&$node, $op, $teaser, $page) {

global $user;

switch ($op) {

case 'view'

if ($user->uid == 0 || !$page) break;

$types_to_annotate = variable_get('annotate_node_types');

if (!in_array($node->type, $types_to_annotate, TRUE)) break;

$result = db_query('SELECT note FROM {annotations} WHERE nid = %d

AND uid = %d', $node->nid, $user->uid);

$node->annotation = db_result($result);

$node->content['annotation_form'] = array(

'#value' => drupal_get_form('annotate_entry_form', $node),

'#weight' => 10

);

}

}


How does drupal work1

How does Drupal Work?

  • Web server tasks:

    • Request arrives at server, e.g. example.com/foo/bar

    • mod_rewrite rules (in .htaccess file) change URL to

      http://example.com/index.php?q=foo/bar

    • Processing begins with index.php, with path (foo/bar) passed in as a GET parameter


How does drupal work2

How does Drupal work?

  • Drupal takes over…

    • Drupal bootstrap process (defined in bootstrap.inc)

      • Initialization: set up internal config array. Process settings.php

      • Open database connection

      • Sessions are initialized or read from database

      • Page cache: Drupal loads enough code to determine whether to serve a page from the page cache

      • Path: code that handles path aliasing is run

      • Full load

      • Process request

      • Theming


Processing the request

Processing the Request

  • Callback function does whatever is required to process request

  • For example, q=node/3:

    • "Callback mapping": URL is mapped to function node_page_view()

    • (A function like node_page_view() is called a "hook")

    • Node module generates output variables

    • Then, it's time for theming


Summary

Summary

  • Modules are defined with .info files

  • Modules implement hooks to do stuff

  • Hooks are functions that are called for each module when system events happen, e.g. page load or user login


  • Login