Drupal development

From Things and Stuff Wiki
Jump to navigation Jump to search


needs refactoring to work with theming

Basics

$variable_name


Drupal.org

see project sidebar links for git, patches pending, etc.

Architecture

  • Drupal dev docs - "Newcomers to Drupal development should read the conceptual information provided in the 'Components of Drupal' section, and then proceed to examine one of the heavily-documented example modules below. The examples are fully-functioning Drupal modules, so you can download them from the contributions repository and alter them as you experiment."

Multisite

Drupal.org

Modules

CLI

Coding

dpm()

Admin

Content

Module Admin

Performance

Boost

  • Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic. For shared hosting this is your best option in terms of improving performance. On dedicated servers, you may want to consider Varnish instead. Apache is fully supported, with Nginx, Lighttpd and IIS 7 semi-supported. Boost will cache & gzip compress html, xml, ajax, css, & javascript. Boosts cache expiration logic is very advanced; it's fairly simple to have different cache lifetimes for different parts of your site. The built in crawler makes sure expired content is quickly regenerated for fast page loading.

CloudFlair

Other

  • Cache Control is a module for integrating your site with the Varnish HTTP accelarator (and other external HTTP-caches) in a fashion that not only allows for caching pageloads for anonymous users but also for authenticated users.

Coding

Patches

patch -p1 < path/file.patch

or

git apply path/file.patch

Hooks

"Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

"To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it."

Menu system (path)

Content

Entities

An entity can be a kind of content stack. An entity base table is tied to fields using bundles. Entity types include node, comment, taxonomy term, user profile, organic group, etc. Entity types can allow bundling or not (creating types of node vs. users, though see the Profile 2 module). Fields are used to store and display various data types, and can be reused across bundles and entities.

(that was about right the last time I dived in)

hook_entity_info - "Inform the base system and the Field API about one or more entity types."

Taxonomy

Ctools

Chaos tool suite (ctools) suite is primarily a set of APIs and tools to improve the developer experience. It also contains a module called the Page Manager whose job is to manage pages. In particular it manages panel pages, but as it grows it will be able to manage far more than just Panels.

For the moment, it includes the following tools:

  • Plugins -- tools to make it easy for modules to let other modules implement plugins from .inc files.
  • Exportables -- tools to make it easier for modules to have objects that live in database or live in code, such as 'default views'.
  • AJAX responder -- tools to make it easier for the server to handle AJAX requests and tell the client what to do with them.
  • Form tools -- tools to make it easier for forms to deal with AJAX.
  • Object caching -- tool to make it easier to edit an object across multiple page requests and cache the editing work.
  • Contexts -- the notion of wrapping objects in a unified wrapper and providing an API to create and accept these contexts as input.
  • Modal dialog -- tool to make it simple to put a form in a modal dialog.
  • Dependent -- a simple form widget to make form items appear and disappear based upon the selections in another item.
  • Content -- pluggable content types used as panes in Panels and other modules like Dashboard.
  • Form wizard -- an API to make multi-step forms much easier.
  • CSS tools -- tools to cache and sanitize CSS easily to make user-input CSS safe.
  • Ctools Plugin Stub is a Drush plugin that can help you generate code stub files for ctools plugins. I wrote this plugin after having consistently messed up names of hook implementations in plugins over a long period. Plugin Stub does not write actual code that *does* stuff for you, but it sets you up so that all you have to do to get started is to fill in the capitalized parts of the generated file and start writing code that *does* stuff.

Menus

JavaScript

Video

Adding a JS file

In theme .info;

scripts[] = scriptfile.js

In template.php;

drupal_add_js()
  first paramater path
  second paramater (goes through as 'type: ' array item, defaults to file)
    file, setting, inline, external
    default: preprocess: true, everypage: true, 
    weight:
$element['#attached']['js']

Drupal JS API and Behaviours

Drupal has an API for passing information between PHP and JS. Drupal.js sets up Drupal namespace.

Render Array

PHP sent by JSON to change content.

jQuery

The .ready() function also has the ability to alias the jQuery object:

jQuery(document).ready(function($) {
  // Code that uses jQuery's $ can follow here.
});

AJAX

JSON