Drupal7 Development

Embed Size (px)

Citation preview

Drupal developmentIntroductie

[email protected]: @haro

Boeken

Video

Lullabot videos (d6): http://store.lullabot.com/ Of www.drupalize.me

Build a module: http://buildamodule.com

www.archive.org: alle Drupalcon conferentie opnames

Drush

Drush: Drupal Shell

Drush = Drupal shell = command line Drupal

http://drupal.org/project/drushhttp://vimeo.com/5207683

Extra http://drupal.org/taxonomy/term/4654

http://www.archive.org/details/DrupalconSf2010Drush

http://www.archive.org/details/DrupalconSf2010AdvancedDrush

Installatie Drush: zie readme.txt file

Drush commando voorbeelden

Drupal installeren in htdocs of www mapjedrush (help uitleg)

drush dl (download drupal)

drush dl cck views nl ckeditor acquia_marina backup_migrate (in drupal map)

drush en cck views (modules aanleggen, omgekeerd: dis)

drush cron

Drupal updaten met drushdrush bam backup of drush sql-dump > example10052010.sql

tar -czf drupal.tgz drupal

drush variable-set site_offline TRUE

drush up: update alle modules + backup code

drush updb: run update.php

drush variable-set site_offline FALSE

Drush make

Drush make: bundelen van de automatisaties

Installeren: drush dl drush_make

Makefile opstellen:Drush generate makefile /opt/lampp/htdocs/makefiles/example.make

Drush convert makefile example.make example.make

drush make example.make example (maakt een drupal site op /example)

Drush make structuur

core = 6.x

projects[] = drupalprojects[] = cckprojects[] = views

Uitgebreid voorbeeld: http://drupalcode.org/viewvc/drupal/contributions/profiles/openatrium/openatrium.make?revision=1.38&view=markup

Werkomgeving

Versie controle

Bij het samenwerken van verschillende mensen aan dezelfde code: bijhouden versies, mergen en oplossen van code conflicten, staging en deployment

Systemen: cvs, svn (centralised repository)

Git, mercurial, bzr (distributed repository)

Populariteit van github noodzaakte drupal.org over te schakelen van de oude cvs naar git op 24 feb 2011

Contributen aan Drupal: http://drupal.org/documentation/git

IDE

Eclipse PDT with the plugin 'PHP debugger support for PDT'.http://drupal.org/project/eclipse: hook_... templates

http://xtnd.us/eclipse/install Drupal for Eclipse

Netbeans

Aptana

Komodo

Coda

Sublime text

Codekit

Debugger

Xdebug

Stap voor stap bekijken wat er allemaal gebeurt na een page request

Breakpoints

Backtrace

https://addons.mozilla.org/en-US/firefox/addon/easy-xdebug/

http://krimson.be/articles/drupal-coding-speed-tips-using-ide

api.drupal.org

Drupal (core) bevat erg veel comments waardoor de handleiding eigenlijk in de code zit

api.drupal.org wordt automatisch opgebouwd met de api module (http://drupal.org/project/api) op basis van Drupal core.

Om een volledige documentatie te hebben van alle modules (dus incl contrib) op je site kun je zelf de api module toepassen of bijvoorbeeld http://api.lullabot.com gebruiken.

Modules upgraden 6->7

http://drupal.org/update/modules/6/7

Coder module kan gedeeltelijk upgrades automatiseren: http://drupal.org/project/coder

Coder live site: http://upgrade.boombatower.com

Drupal coding standards

http://drupal.org/coding-standards

Coder module (http://drupal.org/project/coder)Voorziet een automatische scanning naar fouten tegen coding standards

Devel module

Bestaat uit: Devel, devel generate, devel node_access en devel performance logging

Blokken: development, execute php, switch user

Theme developer voor theming

Execute php: global $user; dsm($user)

Basiscomponenten

Nodes (entities + fields)

Users: global $user, verschil met $account

Blokken

Menus

Views

Drupal database systeem

User: nieuw paswoord via shell script wegens salt

System: alle modules en hun gewichten

Sessions, ...

Drupal bestandsysteem

/modules: core modules

/sites/all/modules: contrib modules

/sites/default/modules: eigen modules (tenzij bij multisite configuratie)

Module opbouw

.info: definitie, dependencies, versie

.module: gewoon php code

.install: wordt geladen bij installatie/enabled, database tabellen en variables

.inc: opsplitsen van diverse delen, vb admin de

.tpl.php: html output

.css: css output

Translations: .po bestanden

Tests php simpletest

Voorbeeldmodules

Alle modules van Drupal coreZijn heel grondig becommentarieerd en door vele programmeurs verfijnd

http://drupal.org/project/examplesVoorbeeldmodules van veelvoorkomende setups

Functies

Veelvoorkomende functies

L();

node_load();

node_view();

Arg();

T();

variable_set(); variable_get(); variable_del();

format_date()

drupal_set_message();

http://www.ventureweb.net/blog/great-drupal-functions

Secure code

http://drupal.org/writing-secure-code

Filteren van datacheck_plain()

check_markup()

t()

filter_xss(): voor admin pagina's

Database queriesGebruik van placeholders

Hooks

Drupal hooks

Don't hack core!

http://api.drupal.org/api/drupal/includes--module.inc/group/hooks

Wijzigingen aanbrengen in Drupal core of andere modules zonder die te modules te wijzigen

Spelen in op bepaalde events die gebeuren tijdens de opbouw van een pagina: Een gebruiker logt in

De node wordt getoond

Het menu wordt opgebouwd

Een formulier wordt verwerkt

hook_form_alter

Mogelijkheid om elk formulier op de site te wijzigen via form api

Form api: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/7: definitie van forms, validate en submit functies

StappenBepaal de form_id

Maak abc_form_FORM_ID_alter in je module

dsm($form) of print_r($form)

Doe de gewenste wijzingen

Andere hooks

hook_help();

hook_menu();

hook_permission(); => user_access();

hook_mail();

hook_user();

hook_block_info();

hook_node_...();

Definitie node

Zie node_example module

hook_entity_...: Nodes zijn een soort van fieldable entities

hook_entity_info(): definitie van de entity die je definieert

Definitie fields

Gebruik van Field api

Zie ook field_example module

hook_field_info()

hook_field_...()

Structuur, schema, validatie, widget, widget_form, formatter

Database layerDBTNG

Db abstraction layer

Abstratie laag gebaseerd op php pdo: Schema apihttp://api.drupal.org/api/drupal

Wordt gedefinieerd in hook_schema() in het .install bestand van de module

Gebruik de Schema module voor definitie www.drupal.org/project/schemaDefinieer lege abc_schema() in .install van je module

Maak je database tabellen met phpmyadmin

Schema module: Inspect tab geeft je de code

Database queries

Gebruik db_query en placeholdershttp://api.drupal.org/api/drupal/includes--database--database.inc/function/db_query/7

Gebruik db_rewrite_sql ivm node_access modules

References

Drupal module development guide:http://drupal.org/developing/modules

Api: http://api.drupal.org

Working with the Drupal api: http://drupal.org/node/326

Field api en fieldable entities maken: http://drupal.org/node/443536

Muokkaa otsikon tekstimuotoa napsauttamalla

Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso