how does drupal work n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
How does Drupal Work? PowerPoint Presentation
Download Presentation
How does Drupal Work?

Loading in 2 Seconds...

play fullscreen
1 / 12

How does Drupal Work? - PowerPoint PPT Presentation


  • 110 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'How does Drupal Work?' - colette-barton


Download Now 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
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