SlideShare a Scribd company logo
Drupal as a Web
Framework
Adam Kalsey
adam@tropo.com
@akalsey

Tropo
www.Tropo.com
@tropo
“A web application framework is a software
framework that is designed to support the
development of dynamic websites, Web
applications and Web services. The
framework aims to alleviate the overhead
associated with common activities
performed in Web development.”


                                - Wikipedia
User
Management
user.module


fields.module
Drupal as a web framework
Drupal as a web framework
Drupal as a web framework
Database Access
$query = db_select('search_index',
'i', array('target' => 'slave'))-
>extend('SearchQuery')-
>extend('PagerDefault');
  $query->join('node', 'n', 'n.nid =
i.sid');
  $query
    ->condition('n.status', 1)
    ->addTag('node_access')
    ->searchExpression($keys, 'node');
$databases['default']['default'] = array(
   'driver' => 'mysql',
   'database' => 'databasename',
   'username' => 'username',
   'password' => 'password',
   'host' => 'localhost',
   'prefix' => 'main_',
   'collation' => 'utf8_general_ci',
);

$databases['default']['default'] = array (
   'database' => 'sites/default/files/.ht.sqlite',
   'driver' => 'sqlite',
   'prefix' => '',
);
function audioblogger_schema() {
  $schema = array();
  $schema['audioblogger'] = array(
    'fields' => array(
    'uid' => array('type' => 'int',
'unsigned' => TRUE, 'not null' => TRUE,
'default' => 0, 'disp-width' => '10'),
    'bloguser' => array('type' =>
'varchar', 'length' => '255', 'not null'
=> TRUE),
$form['audioblogger']['phone'] = array(
  '#type' => 'textfield',
  '#title' => t('Phone'),
  '#default_value' =>
empty($edit['phone']) ? '' :
$edit['phone'],
  '#description' => t('The phone number
you usually will call in from.'));
function audioblogger_menu() {
  $items = array();

  $items['audioblogger/answer'] =
array(
     'page callback' =>
'audioblogger_answer',
     'access arguments' => array('access
content'),
     'type' => MENU_NORMAL_ITEM,
  );
#: includes/common.inc:344 modules/
system/system.admin.inc:1645
msgid "@site is currently under
maintenance. We should be back shortly.
Thank you for your patience."
msgstr ""

#: includes/common.inc:1211 modules/
blogapi/blogapi.module:739;749 modules/
upload/upload.admin.inc:98;107;136;145
msgid "MB"
msgstr ""
<?php if (isset($primary_links)) : ?>
  <?php print theme('links',
$primary_links, array('class' => 'links
primary-links')) ?>
<?php endif; ?>
<?php if (isset($secondary_links)) : ?>
  <?php print theme('links',
$secondary_links, array('class' =>
'links secondary-links')) ?>
<?php endif; ?>
Drupal as a web framework
What about
 MVC?
/**
 * Default implementation of
DrupalEntityControllerInterface.
 *
 * This class can be used as-is by most
simple entity types. Entity types
 * requiring special handling can
extend the class.
 */
class DrupalDefaultEntityController
implements
DrupalEntityControllerInterface {
<?php if (isset($primary_links)) : ?>
  <?php print theme('links',
$primary_links, array('class' =>
'links primary-links')) ?>
<?php endif; ?>
<?php if
(isset($secondary_links)) : ?>
  <?php print theme('links',
$secondary_links, array('class' =>
'links secondary-links')) ?>
<?php endif; ?>
function audioblogger_menu() {
  $items = array();

  $items['audioblogger/answer'] =
array(
     'page callback' =>
'audioblogger_answer',
     'access arguments' =>
array('access content'),
     'type' => MENU_NORMAL_ITEM,
  );
Drupal as a web framework
Drupal as a web framework
Drupal as a web framework
What does Drupal
     need?
Demo time
function frameworkdemo_menu() {
  $items = array();
  $items['demo/answer'] = array(
     'page callback' => 'demo_answer',
     'access arguments' => array('access
content'),
     'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}
function frameworkdemo_answer() {
  include_once 'tropo.class.php';
  $tropo = new Tropo();
  $session = new Session();
  $caller = $session->getFrom();
  $number = $caller['id'];
  $tropo->say('Thanks for coming!');
  $_SESSION['caller'] = $number;
  $tropo->on(array('event' =>
'continue', 'next'=> url('demo/
thanks/')));
  frameworkdemo_save($number);
  print $tropo;
}
www.Tropo.com
Drupal as a web framework
(604) 800-9142
Free developer accounts: http://Tropo.com

Demo module source:
https://github.com/akalsey/drupal-framework-demo

Slides: http://slideshare.com/akalsey/drupal-as-a-web-
framework

Follow us on Twitter: @Tropo
Me: Adam Kalsey | adam@tropo.com | @akalsey

More Related Content

Drupal as a web framework

  • 1. Drupal as a Web Framework
  • 3. “A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. The framework aims to alleviate the overhead associated with common activities performed in Web development.” - Wikipedia
  • 10. $query = db_select('search_index', 'i', array('target' => 'slave'))- >extend('SearchQuery')- >extend('PagerDefault'); $query->join('node', 'n', 'n.nid = i.sid'); $query ->condition('n.status', 1) ->addTag('node_access') ->searchExpression($keys, 'node');
  • 11. $databases['default']['default'] = array( 'driver' => 'mysql', 'database' => 'databasename', 'username' => 'username', 'password' => 'password', 'host' => 'localhost', 'prefix' => 'main_', 'collation' => 'utf8_general_ci', ); $databases['default']['default'] = array ( 'database' => 'sites/default/files/.ht.sqlite', 'driver' => 'sqlite', 'prefix' => '', );
  • 12. function audioblogger_schema() { $schema = array(); $schema['audioblogger'] = array( 'fields' => array( 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'bloguser' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE),
  • 13. $form['audioblogger']['phone'] = array( '#type' => 'textfield', '#title' => t('Phone'), '#default_value' => empty($edit['phone']) ? '' : $edit['phone'], '#description' => t('The phone number you usually will call in from.'));
  • 14. function audioblogger_menu() { $items = array(); $items['audioblogger/answer'] = array( 'page callback' => 'audioblogger_answer', 'access arguments' => array('access content'), 'type' => MENU_NORMAL_ITEM, );
  • 15. #: includes/common.inc:344 modules/ system/system.admin.inc:1645 msgid "@site is currently under maintenance. We should be back shortly. Thank you for your patience." msgstr "" #: includes/common.inc:1211 modules/ blogapi/blogapi.module:739;749 modules/ upload/upload.admin.inc:98;107;136;145 msgid "MB" msgstr ""
  • 16. <?php if (isset($primary_links)) : ?> <?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?> <?php endif; ?> <?php if (isset($secondary_links)) : ?> <?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?> <?php endif; ?>
  • 19. /** * Default implementation of DrupalEntityControllerInterface. * * This class can be used as-is by most simple entity types. Entity types * requiring special handling can extend the class. */ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
  • 20. <?php if (isset($primary_links)) : ?> <?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?> <?php endif; ?> <?php if (isset($secondary_links)) : ?> <?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?> <?php endif; ?>
  • 21. function audioblogger_menu() { $items = array(); $items['audioblogger/answer'] = array( 'page callback' => 'audioblogger_answer', 'access arguments' => array('access content'), 'type' => MENU_NORMAL_ITEM, );
  • 27. function frameworkdemo_menu() { $items = array(); $items['demo/answer'] = array( 'page callback' => 'demo_answer', 'access arguments' => array('access content'), 'type' => MENU_NORMAL_ITEM, ); return $items; }
  • 28. function frameworkdemo_answer() { include_once 'tropo.class.php'; $tropo = new Tropo(); $session = new Session(); $caller = $session->getFrom(); $number = $caller['id']; $tropo->say('Thanks for coming!'); $_SESSION['caller'] = $number; $tropo->on(array('event' => 'continue', 'next'=> url('demo/ thanks/'))); frameworkdemo_save($number); print $tropo; }
  • 32. Free developer accounts: http://Tropo.com Demo module source: https://github.com/akalsey/drupal-framework-demo Slides: http://slideshare.com/akalsey/drupal-as-a-web- framework Follow us on Twitter: @Tropo Me: Adam Kalsey | adam@tropo.com | @akalsey