Drupal
Published: 03:11, Monday 25 July 2011
Notes
What's this? See my article about Notes.
View as plain text file.
documentation: http://drupal.org/handbooks
glossary: http://drupal.org/glossary
why drupal does not use classes: http://drupal.org/node/547518
install
importing language takes too much time
change max_execution_time in php.ini
need to wait quite some time
restart: remove all tables from db and go to install.php
multi-site
multisite manager module
doesn't work in drupal 7.x!
video
use virtual host
document root: is the same for all sites!
new site manually:
create a new db
mkdir sites/sitename
sitename can be example.com, sub.example.com, example.com.subdir, 8080.example.com
subdirs
ln -s drupaldir subdir
local: sitename is localhost.subdir
cp sites/default/default.settings.php sites/newsite/settings.php
adjust rights
site-specific modules and themes:
create themes and modules dirs in site dir
admin login: /user (?q=user)
philosophy/basics
all is nodes
every node has exactly one path
all commentable (2nd class citizens)
has a content type
content types:
core:
article
basic page
blog entry
book page
comment
(comment)
forum
poll
add: administer > structure > content types
structure: menus, views, blocks
flow:
template
user permissions
admin/people/permissions
blocks & menus
modules
data (nodes etc)
admin
user 1: give it only to a developer
dashboard
overlay: overlay is a really cool thing
shortcuts
can be put off line!
registration
disallow via config/people/accounts
not in the rights
backup:
modules
backup and migrate module: http://drupal.org/project/backup_migrate
backup the db, the core files, the non-core files
backup scripts:
backup: http://drupal.org/node/59373
restore: http://drupal.org/node/59377
multisite: http://drupal.org/node/310948
upgrade/update core:
minor versions
UPGRADE.txt
remove all files except 'sites' and custom
rm -r !(sites)
rm -r !(test|backup|sites|favicon.ico)
yes, modules are preserved anyway, somehow
unzip new version
/update.php
if necessary: in settings.php $update_free_access = TRUE;
.htaccess and robots.txt will need to be rechanged afterwards
favicon.ico (if you don't use favicon module)
check permissions
try to restore all the core hacks :)
migration/local/remote/go live
maybe there's a module for this?
document all the php/mysql/apache installation differences
server checklist: http://drupal.org/node/333675
old:
document used modules: http://drupal.org/project/sitedoc
off line, update
turn off clean urls: admin/config/search/clean-urls
clear cache tables, export db
upload drupal code, files, sql data
modify settings.php, .htaccess
log on, change site information, adjust modules
check status report, adjust performance parameters
set on line
set up cron job
is configurable via backend
set the dns
structure
node reference/content reference fields/user reference fields: need references module : http://drupal.org/project/references
backreferences/back reference:
corresponding node reference: http://drupal.org/project/cnr
book module: for structured documents
comments: can add fields for a content type
menu
collections of links for navigation
modify via admin/structure/menu
add to page via admin/structure/block
can add dropdown menus: http://drupal.org/node/206653
modules: http://drupal.org/node/627128
content type display/display modes/display type/content type view modes/node view modes/custom view mode:
default: full, teaser
custom display/add more:
hook_entity_alter:
function niki_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['integrated'] = array(
'label' => t('Integrated full'),
'custom settings' => TRUE,
);
}
in templates check $view_mode
workarounds:
http://stackoverflow.com/questions/2248592/add-another-node-display-like-teaser-full-node-to-drupal
use preprocessing
use the given variables (see [[#template variables]])
views:
module: http://drupal.org/project/views
ctools: http://drupal.org/project/ctools
help: admin/advanced_help/views
concepts:
fields, relationships, sort criteria, filters
displays:
page display
block display
header, footer, empty text
arguments/contextual filters
will be accessible via $view->args
insert views programmatically/include views in code
$display = views_get_view(name)->execute_display(display_id, args);
print $display;
sometimes:
print $display['subject'];
print $display['content'];
alter view sql query/custom sql for views
hook_views_pre_execute(&$view)
$view->build_info['query']
it's an object, alter with [[#orm]]
$view->build_info['query_args'];
modules
check
gallery/slideshow:
the problem (my post): http://drupal.org/node/1248314
my choice: colorbox module
field slideshow: http://drupal.org/project/field_slideshow
colorbox module
very good tutorial:
http://vimeo.com/26411524
uses cool style for field slideshow
views slideshow module: http://drupal.org/project/views_slideshow
config/media/image_styles
galleriffic
creating a view from galleriffic template produces a php error
rotating banner: http://drupal.org/project/rotating_banner
media gallery: http://drupal.org/project/media_gallery
display block: http://drupal.org/project/ddblock
galleria: http://drupal.org/project/galleria
entity views attachment: http://drupal.org/project/eva
blocks:
admin/structure/blocks
boxes of contents that can be displayed in regions
regions: depend on theme
throttle module: hide blocks during high server loads
php snippet for visibility: http://drupal.org/node/60317
links/related content:
modules: http://drupal.org/node/645794
users:
profiles can be extended: http://drupal.org/documentation/modules/profile
taxonomy: admin/user/user_terms
mobile: http://drupal.org/node/646294
panels: http://drupal.org/node/627126
languages: http://drupal.org/node/324602
build
use test sites
drupal folder:
can be moved without problems
remote:
put in a subfolder
modify sites/default/settings.php $base_url to link to root
redirect from root
RewriteEngine on
RewriteRule (.*) drupa.l/$1 [L]
actions: http://drupal.org/node/206811
workflows/revisioning: http://drupal.org/node/417694
commerce/ads: http://drupal.org/node/206719
other sites/systems/data: http://drupal.org/node/627270
content display: http://drupal.org/node/206776
content
content recommendations: http://drupal.org/node/1207628
dates/events: http://drupal.org/node/627222
distributions/installation profiles: http://drupal.org/documentation/build/distributions
documentation tools: http://drupal.org/node/779268
email/messagging:
mask email addresses: spamspan module: http://drupal.org/project/spamspan
forms
geographic information
input formats
media and files
file module: http://drupal.org/documentation/modules/file
images:
gallery module: does not work in 7.x
image field: part of core
insert module
image in the node body text
admin/config/content/formats/filtered_html and full_html add convert media tags into markup
in filtered_html allow <img>
doesn't really display them correctly
watermark
imagecache actions
imagecache can't change the original
private files/protect original images
create private filesystem
change field config
content access module: http://drupal.org/project/content_access
imagecache actions module: http://drupal.org/project/imagecache_actions
search
search engine optimization
site building
social networking/collaboration
user-generated content
utility
howtos: to check
site recipes: to check
home page
default: blog style teaser listing
php page snippets
activate php filter module
theme/theming
contributed themes:
theming videos: http://drupal.org/node/136502
settings:
admin/appearance/settings/themename
advanced: http://drupal.org/node/177868
theme folder
location: sites/all/themes/example
contains:
example.info
defines block regions
defines styles
is cached: need to clear the cache on change
comments: ; Comment
values: key = value or "value"
name = The theme name
description = The description of the theme
[screenshot = screenshot.png]
core = 7.x
engine = phptemplate
base theme = parent
in subthemes
regions:
regions[identifier] = Region name
default 7.x:
regions[header] = Header
regions[highlighted] = Highlighted
regions[help] = Help
regions[content] = Content
mandatory in all themes
regions[sidebar_first] = Left sidebar
regions[sidebar_second] = Right sidebar
regions[footer] = Footer
manually add block into a region:
drupal_set_content(regionname, blockstring)
inside page.tpl.php:
check if region is occupied: $page[regionname]
display a region/render a region: print render($page[regionname])
find content type of node: node_type_get_type($node)->type
features/theme settings:
can be toggled on and off on config page
default 7.x:
features[] = logo
features[] = name
features[] = slogan
features[] = node_user_picture
features[] = comment_user_picture
features[] = favicon
features[] = main_menu
features[] = secondary_menu
stylesheets:
stylesheets[all][] = style.css
all, screen, projection, print
via the api: drupal_add_css, drupal_get_css
browser-specific: http://drupal.org/node/744328
scripts:
scripts[] = myscript.js
add javascript: http://drupal.org/node/171213
[php = 5.2]
default: DRUPAL_MINIMUM_PHP
style.css
html.tpl.php
page.tpl.php
region.tpl.php
block.tpl.php
node.tpl.php
comment-wrapper.php
comment.tpl.php
template.php
for preprocessors
custom functions
overriding theme functions
must start with <?php but omit close tag
logo.png
recommended for contribution
screenshot.png
recommended for contribution
images folder
default themes:
bartik, garland, minnelli
don't modify: they are used for install and upgrade
copy a theme:
copy an other and modify .info
local: local.css
use firebug
templates
templatename.tpl.php
main: page.tpl.php
core templates
aggregator, block, book, comment, field, forum, node, overlay, poll, profile, search, system, taxonomy, toolbar, user
suggestions
alternate templates, used conditionally
block--[region|[module|--delta]].tpl.php
block.tpl.php
comment--[node-type].tpl.php
comment.tpl.php
page--[front|internalpath].tpl.php
node/1/edit suggestions:
page.tpl.php
page--node.tpl.php
page--node--%.tpl.php
because 1 is a number
page--node--1.tpl.php
page--node--edit.tpl.php
page--front.tpl.php
if node/1/edit is the front page (?)
node--[type|nodeid].tpl.php
to define content by node type
...
more info: http://drupal.org/node/223440
view templates
copy from sites/all/modules/views/theme/templatename to the theme and modify
views-view-unformatted.tpl.php
template variables
default:
$attributes_array
$title_attributes_array
$content_attributes_array
$classes_array
$title_prefix
$title_suffix
$id
$directory
$is_admin
$is_front
$logged_in
$db_is_active
$user
view mode: $view_mode if you created a custom view mode
view: if template is called from a view then check $view->name
functions:
hooks: page, node, comment, block
attributes: (&$variables)
template_preprocess[_hook]
modulename_preprocess[_hook]
enginename_preprocess[_hook]
themename_preprocess[_hook]
also drop_preprocess(&$variables, $hook)
performance
theme cache/theme registry:
clear in admin/config/development/performance
or visit admin/appearance
rebuild automatically: checkbox in admin/appearance/settings/themename
theming webform: http://drupal.org/node/1157306
css classes:
.menu
.block
.links
lists of links
.node
wrapper div around any node including title
.node-title
.content
body of a node
.terms
taxonomy terms, also .links and .inline
.inline
ul items into horizontal line
.feed-icon
.clearfix
right to left (rtl) languages: http://drupal.org/node/222782
overriding module html:
have to look for the themable output in the module directory
override tpl.php: copy it to theme dir
override preprocess function
and copy the function to your tpl.php
change the function name: theme_xxx to mytheme_xxx
modify the copied code
refresh theme cache
override order: core, modules, theme engine, theme
customize login/register/password: http://drupal.org/node/350634
core blocks:
block-forum-active
block-profile-author-information
block-book-navigation
block-locale-language-switcher
plock-poll-recent
block-system-navigation
block-forum-new
block-statistics-popular
block-system-powered-by
block-blog-recent
block-comment-recent
block-search-form
block-node-syndicate
block-user-login
block-user-new
block-user-online
menu theming
main menu: is integrated in layout, no need to add it as block
custom entities: http://drupal.org/node/1238606
theming modules:
developer
parts of pages show functions/templates that outputted it
color module
allows admin to change the color scheme
colors:
base color, link color, top header, bottom header, text color
color theme subfolder
base.png should be a layered file
color.inc
makes color picker appear on theme's settings
a partial php file
preview.css
preview.png
live css, custom node template, formatted title, sections, signwriter, skinr, typeface documentation, noie6, recommended target browser, create screenshots
scaffold
looks cool!
theme editor
admin/theme_editor
semantics: http://drupal.org/node/44072
starter themes
zen
create a subtheme: http://drupal.org/node/1010576
layout
main { content, navbar, sidebar-left, sidebar-right }
the order of the elements is for search engines and accessibility
the elements are reordered visually with negative right margins
best practices
use test site, write secure code, deploy by role
switchtheme module
only certain roles can switch theme
conventions
2 spaces per indent
distinguish between html and php indentation
prefer php in html and not the opposite
separate logic from presentation
always put semicolon
accessibility: http://drupal.org/node/464472
try on different browsers
validate
howtos: http://drupal.org/node/22803
snippets: http://drupal.org/node/45471
core themes: bartik, seven, stark, garland
breadcrumbs:
remove: need to do in page.tpl.php
background images:
url relative to css sheet
favicon module
doesn't really work for me (development version)
develop
environment:
test site
is recreated as needed as a copy of the production site
how I do it:
with multi-sites
I just copy the database, keep the rest, do my tests, redo on production site
how they explain it
needed:
shell access, two mysql databases
create test site:
copy files and db
edit settings.php
base_url, db_url, site_name
perform tests
go live:
redo actions on production
or copy the test site into production
remove the test site
local mail: http://drupal.org/node/201981
devel modules: http://drupal.org/node/206773
vim config
drupal for firebug: http://drupal.org/project/drupalforfirebug
custom module/module development
module name must be unique also among themes
sites/all/modules/modulename
modulename.module
no .php extension
start with <?php
no ?>
use hooks
modulename_functionname()
hooks are cached, empty it
modulename.info
name = Module name
description = description
core = 7.x
files[] = example.test
dependencies[] = modulename
package = grouping string
comments:
doxygen
/**
* @file
* File description
*/
show errors
settings.php:
error_reporting(-1);
$conf['error_level'] = 2;
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
api
link
l(text, alias)
automatically finds unique id
simpletest
drupal's testing framework
installation profiles: http://drupal.org/node/159730
database/sql/mysql
database api/orm
dynamic queries
$query = db_select('node', 'n', $options);
->fields('n');
->fields('u', array('uid', 'name', 'status', 'created', 'access'))
->addField('n', 'title', 'my_title');
->condition('u.uid', 0, '<>')
->join(table, 'u', 'n.uid = u.uid AND u.uid = :uid', array(':uid' => 5));
join, innerjoin, leftjoin, rightjoin
table can be tablename or select object
->distinct()
->addExpression('COUNT(uid)', 'uid_count');
->addExpression('created - :offset', 'uid_count', array(':offset' => 3600));
->orderBy('title', 'DESC');
->orderRandom();
->groupBy('uid');
->range(0, 50);
$result = $query->execute();
conditions
->condition($field, $value = NULL, $operator = '=')
->where($snippet, $args = array())
->condition('myfield', array(1, 2, 3), 'IN');
->condition('myfield', array(5, 10), 'BETWEEN');
->isNull('myfield')
->isNotNull('myfield');
nested:
->condition(db_or()->condition(...
db_and()
db_or()
db_xor()
subselects:
->condition(SelectQuery object, ...
node
nid, vid, type, language, title, uid, status, created, changed, comment, promote, sticky, tnid, translate
field_data_field_fieldname
entity_type, bundle, deleted, entity_id, revision_id, language, delta, field_fieldname_nid
error reporting
at the beginning of index.php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
modules
lists:
top10
views, token, admin menu, date, IMCE, google analytics, webform, chaos tool suite
transliteration
pathauto
better urls automatically, requires token and transliteration
wysiwyg
in config activate wanted buttons
don't activate: bbcode
in admin/config/content/formats/filtered_html allow <p> tag
core:
content construction kit (cck):
is in core (kinda)
taxonomy: categories
contextual links
add new: http://drupal.org/node/1089922
location
associate geographic locations with nodes
contact module: http://drupal.org/documentation/modules/contact
main page/home page/front page:
block only on front page: in block settings, pages use <front> tag
front page module
different page at beginning
google maps: http://drupal.org/project/gmap
Write a Comment
* These fields are mandatory.